GVKun编程网logo

根据laravel中复选框的选择计算总值(layui获取复选框选中的值)

12

在本文中,我们将为您详细介绍根据laravel中复选框的选择计算总值的相关知识,并且为您解答关于layui获取复选框选中的值的疑问,此外,我们还会提供一些关于android–只选择一个启动首选项复选框

在本文中,我们将为您详细介绍根据laravel中复选框的选择计算总值的相关知识,并且为您解答关于layui获取复选框选中的值的疑问,此外,我们还会提供一些关于android – 只选择一个启动首选项复选框的复选框、angularjs – angular复选框,使用ng-click重置绑定到复选框的ng-model,从而防止取消选中该复选框、angularjs – 如何根据angular.js中的子复选框选择父复选框?、angularjs – 如果选中复选框,则调用具有true值的函数,如果未选中复选框,则调用false值的有用信息。

本文目录一览:

根据laravel中复选框的选择计算总值(layui获取复选框选中的值)

根据laravel中复选框的选择计算总值(layui获取复选框选中的值)

如何解决根据laravel中复选框的选择计算总值?

在我的 Laravel 应用程序中,我有一组从我的数据库加载的复选框。

在我的桌子上,我有 Test_name 和 Test_charge 列。

我正在将上表中的数据加载到前端刀片中

<br>

            @foreach($ttype as $value)

                <label>{{ Form::checkBox(''samp_list[]'',$value->Test_name,false,array(''class'' => ''name'')) }}

                {{ $value->test_name }}</label>

            <br/>

            @endforeach

这可以正确加载,但现在我的问题是这样的,

我在同一个表单中有一个文本字段来提交总测试费用。

 {!! Form::text(''samp_charges'',null,array(''placeholder'' => ''Registration Charges'',''class'' => ''form-control'')) !!}

一旦选中复选框,该总费用必须自动计算并显示在该文本字段中。您单击的框越多,您获得的总数就越多。每个不同的测试费用不同,保存在“Test_charge”列中。

我找到了解决方案 here,但它无法使用,因为我已经将我的 Test_name 作为复选框值属性传递了。如果为了使用它,我必须通过我的 Test_charge 作为 value 属性...

有什么办法可以解决这个问题吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

android – 只选择一个启动首选项复选框的复选框

android – 只选择一个启动首选项复选框的复选框

我有应用程序启动取决于用户优先与三个不同的复选框:

1-启动应用程序没有飞溅和音乐.

2-启动应用程序只有启动.

3-启动应用程序与spalsh和音乐.

以下代码完美的工作.

但仍有两点要做:

首先只应选中一个复选框.

在你选择了任何一个复选框之后,你可以回到mainactivity,在这里你可以通过使用我在选项菜单中已经拥有它的后退按钮或退出按钮退出应用程序,问题是使用后退按钮或退出按钮它不响应第一次单击,我必须单击两次退出应用程序.

但我无法实现它,

任何帮助,请将不胜感激.

public class Splash extends Activity{   
MediaPlayer ourSong;
@Override
protected void onCreate(Bundle savedInstanceState) {
    this.requestwindowFeature(Window.FEATURE_NO_TITLE); 
    // Todo Auto-generated method stub
    super.onCreate(savedInstanceState);
         setContentView(R.layout.splash);  

         SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());                 

         boolean without_splash_screen = getPrefs.getBoolean("without_splash_screen", true);
            if (without_splash_screen == true)
            {   
                Intent intent = new Intent(Splash.this, MainActivity.class);                                     
                startActivity(intent);
            }

    boolean splash = getPrefs.getBoolean("splash", true);       
    if(splash == true) {
        setContentView(R.layout.splash);  
        Thread timer = new Thread()
        {
            public void run()
            {
                try
                {
                    sleep(2000); 
                }
                catch (InterruptedException e)
                {
                    e.printstacktrace(); 
                }
                finally
                {
                    Intent intent = new Intent(Splash.this, MainActivity.class);                                     
                    startActivity(intent);  
                }
            }                          
        };
        timer.start();   
    }                 

    ourSong = MediaPlayer.create(Splash.this, R.raw.splashsound); 

    SharedPreferences getPrefs1 = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    boolean music = getPrefs1.getBoolean("splash_music", true);
    if (music == true)      
    ourSong.start();

    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(2000); }
              catch (InterruptedException e){
                e.printstacktrace(); }
              finally{
                  Intent intent = new Intent(Splash.this, MainActivity.class);                                     
                  startActivity(intent); }}                                 
                                };
         timer.start();   }

@Override
protected void onPause() {
            // Todo Auto-generated method stub
    super.onPause();
    ourSong.release();
    finish();
          } 
       }

在xml文件夹中:prefs.xml

 <?xml version="1.0" encoding="utf-8" ?> 
  <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

    <CheckBoxPreference android:title="without splash screen" 
              android:defaultValue="true" 
              android:key="without_splash_screen" 
              android:summary="Start app without splash"/> 

    <CheckBoxPreference android:title="splash screen" 
              android:defaultValue="true" 
              android:key="splash" 
              android:summary="Start app with splash only" />

    <CheckBoxPreference android:title="splash screen music" 
              android:defaultValue="true" 
              android:key="splash_music" 
              android:summary="Start app with splash and music" /> 

 </PreferenceScreen>

更新:

我也试过下面的代码,但它没有改变任何东西,仍然可以检查所有chechBox:

public class Splash extends Activity{   
MediaPlayer ourSong;

@Override
protected void onCreate(Bundle savedInstanceState) {
    this.requestwindowFeature(Window.FEATURE_NO_TITLE); 
    // Todo Auto-generated method stub
    super.onCreate(savedInstanceState);
         setContentView(R.layout.splash);  

     SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());                 

         boolean without_splash_screen = getPrefs.getBoolean("without_splash_screen", true);
            if (without_splash_screen == true)               
            {   
                Intent intent = new Intent(Splash.this, MainActivity.class);                                     
                startActivity(intent);                      
            }
    boolean splash = getPrefs.getBoolean("splash", true);       
    if(splash == true) {
        setContentView(R.layout.splash);  
        Thread timer = new Thread()
        {
            public void run()
            {
                try
                {
                    sleep(2000); 
                }
                catch (InterruptedException e)
                {
                    e.printstacktrace(); 
                }
                finally
                {
                    Intent intent = new Intent(Splash.this, MainActivity.class);                                     
                    startActivity(intent);
                }
            }                          
        };
        timer.start();   
    }                    
    ourSong = MediaPlayer.create(Splash.this, R.raw.splashsound); 

    SharedPreferences getPrefs1 = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    boolean music = getPrefs1.getBoolean("splash_music", true);
    if (music == true)      
    ourSong.start();

    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(2000); 
                }
              catch (InterruptedException e){
                e.printstacktrace(); 
                }
              finally{
                  Intent intent = new Intent(Splash.this, MainActivity.class);                                     
                    startActivity(intent);
                    }
            }
        };                                                                      
         timer.start();  
         }      
public void getPrefs() {  
    SharedPreferences getPrefs = PreferenceManager  
                    .getDefaultSharedPreferences(getBaseContext());  

    boolean without_splash_screen = getPrefs.getBoolean("without_splash_screen", true);
    boolean splash = getPrefs.getBoolean("splash", false);       
    boolean music = getPrefs.getBoolean("splash_music", false);

    if (without_splash_screen == true){  
        splash = false; 
        music = false;                  
       }else if (splash == true){  
        music = false; 
        without_splash_screen = false;                       
       }else if (music == true){  
        without_splash_screen = false; 
        splash = false;  
    }
    }
   @Override
   protected void onPause() {
// Todo Auto-generated method stub
super.onPause();
ourSong.release();
finish();
  }
  }

更新:
我还尝试了另一个代码,但它没有改变任何东西,仍然可以检查所有chechBox:

  public class Splash extends Activity{   
    MediaPlayer ourSong;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    this.requestwindowFeature(Window.FEATURE_NO_TITLE); 
     // Todo Auto-generated method stub
    super.onCreate(savedInstanceState);
      setContentView(R.layout.splash);  

     SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());                 

     boolean without_splash_screen = getPrefs.getBoolean("without_splash_screen", true);
        if (without_splash_screen == true)
        {   
            Intent intent = new Intent(Splash.this, MainActivity.class);                                     
            startActivity(intent);
        }
        else {       
            getPrefs.getBoolean("splash", false);       
            getPrefs.getBoolean("splash_music", false);
            }
boolean splash = getPrefs.getBoolean("splash", true);       
if(splash == true) {
    setContentView(R.layout.splash);  
    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(2000); 
                }
            catch (InterruptedException e){
                e.printstacktrace(); 
                }
            finally{
                Intent intent = new Intent(Splash.this, MainActivity.class);                                     
                startActivity(intent);  
                }
            } 
        };                             
    timer.start();   
    }                
else
{
    getPrefs.getBoolean("without_splash_screen", false);       
    getPrefs.getBoolean("splash_music", false);
    }
ourSong = MediaPlayer.create(Splash.this, R.raw.splashsound); 
boolean splash_music = getPrefs.getBoolean("splash_music", true);
if (splash_music == true)   {
    ourSong.start();
    setContentView(R.layout.splash);      
Thread timer = new Thread(){
    public void run(){
        try{
            sleep(2000); 
            }
          catch (InterruptedException e){
            e.printstacktrace(); 
            }
          finally{
              Intent intent = new Intent(Splash.this, MainActivity.class);                                     
              startActivity(intent); 
          }
      }                          
  };
  timer.start();   
  }                   
 else
  {
getPrefs.getBoolean("without_splash_screen", false);       
getPrefs.getBoolean("splash", false);
 }
   }
 @Override
 protected void onPause() {
  // Todo Auto-generated method stub
  super.onPause();
  ourSong.release();
  finish();
      } 
   }

有任何建议,谢谢.

更新3(整个项目):

1-一个复选框检查完美.

2-使用MainActivity中的后退按钮或退出按钮,不响应第一次点击,我必须单击两次或三次才能退出应用程序.

Splash.java

  public class Splash extends Activity{ 
MediaPlayer ourSong;
@Override
protected void onCreate(Bundle DrTsn) {
    this.requestwindowFeature(Window.FEATURE_NO_TITLE); 
    // Todo Auto-generated method stub
    super.onCreate(DrTsn);
         setContentView(R.layout.splash);  

         SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());                 

         boolean without_splash_screen = getPrefs.getBoolean("without_splash_screen", true);
            if (without_splash_screen == true)
            {                                              
                Intent intent = new Intent(Splash.this, MainActivity.class);                                     
                  startActivity(intent);                        
            }

    boolean splash = getPrefs.getBoolean("splash", true);       
    if(splash == true) {
        setContentView(R.layout.splash);  
        Thread timer = new Thread()
        {
            public void run()
            {
                try
                {
                    sleep(2000); 
                }
                catch (InterruptedException e)
                {
                    e.printstacktrace(); 
                }
                finally
                {
                    Intent intent = new Intent(Splash.this, MainActivity.class);                                     
                    startActivity(intent);  
                }
            }                          
        };
        timer.start();   
    }                    
    ourSong = MediaPlayer.create(Splash.this, R.raw.splashsound); 

    SharedPreferences getPrefs1 = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    boolean music = getPrefs1.getBoolean("splash_music", true);
    if (music == true)      
    ourSong.start();

    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(2000); 
                }
              catch (InterruptedException e){
                e.printstacktrace(); 
                }
              finally{
                  Intent intent = new Intent(Splash.this, MainActivity.class);                                     
                  startActivity(intent); 
                  }
            }
        };                                                                      
         timer.start();   
         }  
@Override
protected void onPause() {
            // Todo Auto-generated method stub
    super.onPause();
    ourSong.release();
    finish();
          } 
       }

Prefs.java

 public class Prefs extends PreferenceActivity {
  CheckBoxPreference splash;
  CheckBoxPreference splash_music;
  CheckBoxPreference no_splash_music;

 @SuppressWarnings("deprecation")
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   // Todo Auto-generated method stub
   super.onCreate(savedInstanceState);

   addPreferencesFromresource(R.xml.prefs);

  splash = (CheckBoxPreference) findPreference("splash");
  splash_music = (CheckBoxPreference) findPreference("splash_music");
  no_splash_music = (CheckBoxPreference) findPreference("without_splash_screen");

  splash.setonPreferencechangelistener(new OnPreferencechangelistener() {

    @Override
    public boolean onPreferenceChange(Preference preference,
            Object newValue) {
        // Todo Auto-generated method stub

        splash.setChecked(true);
        splash_music.setChecked(false);
        no_splash_music.setChecked(false);

        return true;
    }

});

splash_music
        .setonPreferencechangelistener(new OnPreferencechangelistener() {

            @Override
            public boolean onPreferenceChange(Preference preference,
                    Object newValue) {
                // Todo Auto-generated method stub

                splash.setChecked(false);
                splash_music.setChecked(true);
                no_splash_music.setChecked(false);

                return true;
            }

        });

no_splash_music
        .setonPreferencechangelistener(new OnPreferencechangelistener() {

            @Override
            public boolean onPreferenceChange(Preference preference,
                    Object newValue) {
                // Todo Auto-generated method stub

                splash.setChecked(false);
                splash_music.setChecked(false);
                no_splash_music.setChecked(true);

                return true;
            }
        });
  }
  }

MainActivity.java

  public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {

MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.cool_menu, menu);

getLayoutInflater().setFactory(new Factory() {
public View onCreateView(String name, Context context,AttributeSet attrs) {

if (name .equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) {
try {
LayoutInflater li = LayoutInflater.from(context);
final View view = li.createView(name, null, attrs);

new Handler().post(new Runnable() {
public void run() {

((TextView) view).setTextSize(25);  
((TextView) view).setTextColor(Color.RED); 
} 
}
);                                        
return view;
}
 catch (InflateException e) {        
 }
  catch (ClassNotFoundException e) {          
  }
}                                  
return null; 
}
}
);           
return super.onCreateOptionsMenu(menu);                                    
}   
@Override
public boolean onoptionsItemSelected(MenuItem item) {
    // Todo Auto-generated method stub
    switch (item.getItemId()) {
    case R.id.aboutUs:
        Intent i = new Intent("com.example.checkBox.ABOUT");
        startActivity(i);
    break;
    case R.id.preferences:
        Intent p = new Intent("com.example.checkBox.PREFS");
        startActivity(p);
    break;
    case R.id.exit:
        finish();
    break;
}
return false;
   }
@Override
public void onBackpressed() {
    finish();
}
   }

AboutUs.java

     public class AboutUs extends Activity {
     @Override
   protected void onCreate(Bundle savedInstanceState) {
    // Todo Auto-generated method stub
      super.onCreate(savedInstanceState);
      this.requestwindowFeature(Window.FEATURE_NO_TITLE); 
      setContentView(R.layout.about);  

      Button button = (Button)findViewById(R.id.about_button);           
    button.setonClickListener(new OnClickListener() {
   public void onClick(View v) {
              finish(); }
                      }
                  );}
                 }

解决方法:

“首先应选中一个复选框.”

不知道如何使这个简短而简单的答案,但与我同在,这是有效的.

创建您从活动中调用的首选项活动.

在onoptionSelected中使用类似的东西:

  case R.id.prefs:
        Intent p = new Intent(MainActivity.this, Prefs.class);
        startActivity(p);
        break;

这是Prefs.class

public class Prefs extends PreferenceActivity {
CheckBoxPreference splash;
CheckBoxPreference splash_music;
CheckBoxPreference no_splash_music;


@Override
protected void onCreate(Bundle savedInstanceState) {
    // Todo Auto-generated method stub
    super.onCreate(savedInstanceState);

    addPreferencesFromresource(R.xml.prefs);



    splash = (CheckBoxPreference) findPreference("splash");
    splash_music = (CheckBoxPreference) findPreference("splash_music");
    no_splash_music = (CheckBoxPreference) findPreference("without_splash_screen");

    splash.setonPreferencechangelistener(new OnPreferencechangelistener() {

        @Override
        public boolean onPreferenceChange(Preference preference,
                Object newValue) {
            // Todo Auto-generated method stub

            splash.setChecked(true);
            splash_music.setChecked(false);
            no_splash_music.setChecked(false);

            return true;
        }

    });

    splash_music
            .setonPreferencechangelistener(new OnPreferencechangelistener() {

                @Override
                public boolean onPreferenceChange(Preference preference,
                        Object newValue) {
                    // Todo Auto-generated method stub

                    splash.setChecked(false);
                    splash_music.setChecked(true);
                    no_splash_music.setChecked(false);

                    return true;
                }

            });

    no_splash_music
            .setonPreferencechangelistener(new OnPreferencechangelistener() {

                @Override
                public boolean onPreferenceChange(Preference preference,
                        Object newValue) {
                    // Todo Auto-generated method stub

                    splash.setChecked(false);
                    splash_music.setChecked(false);
                    no_splash_music.setChecked(true);

                    return true;
                }

            });

   }

 }

并且不要忘记将它添加到Manifest:

  <activity
        android:name="com.lordmarty.testforlools.Prefs"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.lordmarty.testforlools.PREFS" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

prefs.xml文件与您发布的文件相同.

如果您有任何错误,请告诉我.我测试了它,它在这里工作正常.

“第二”

不知道你为什么要点击两次.但它可能是由于没有完成,只是调用一个新意图引起的.
尝试从启动你的主要类的地方:

  finally{
            Intent intent = new Intent(Splash.this,    MainActivity.class);                                     
            startActivity(intent);
            finish();

            }

现在,我已经查看了你的项目,并找出了它为何如此错误.

主要原因:

     if (music == true)     
    ourSong.start();

    Thread timer = new Thread(){

这里缺少if语句的括号,导致线程每次都运行.因此,您有两个MainActivities同时运行.

其他说明:对所有值使用“if”.我建议你使用“else if”.

我做了一个小小的清理工作.

你去吧.请享用:

Link to Splash.java

您可以通过多种方式解决最后一个问题.其中一个是这样的:

// add this below the other if else if statements in the splass.java
else if(without_splash_screen == false && splash == false && music == false){
//put whatever you want to happen if none of them are checked. This is just an example.
setContentView(R.layout.splash); 
        setContentView(R.layout.splash); 
        Thread timer = new Thread() { 
            public void run() { 
                try { 
                    sleep(2000); 
                } catch (InterruptedException e) { 
                    e.printstacktrace(); 
                } finally { 
                    Intent intent = new Intent(Splash.this, 
                            MainActivity.class); 
                    startActivity(intent); 
                    finish(); 


                } 
            } 
        }; 
        timer.start(); 

angularjs – angular复选框,使用ng-click重置绑定到复选框的ng-model,从而防止取消选中该复选框

angularjs – angular复选框,使用ng-click重置绑定到复选框的ng-model,从而防止取消选中该复选框

我有一些逻辑,在某些情况下,我希望第一个复选框一直检查.因此,如果用户尝试取消选中它,我想使用ng-click将绑定的ng-model更改为“true”.但复选框仍未取消选中….

我如何实现保持复选框保持基于ng-model的值检查,而不使用angular.element(elem).attr(“checked”,true)之类的东西

<input type = 'checkBox' ng-model = 'checkBoxValue' ng-click = "handler"/>

在控制器中

$scope.checkBoxValue = false;
$scope.handler = function(){
    $scope.checkBoxValue = true;
}

我希望复选框保持检查,因为ng-model checkBoxValue是真的……但显然我在这里错过了一些东西

这是羽毛球:http://plnkr.co/edit/WbjZilFLDfbP3mQ4oMgx?p=preview

我进入调用堆栈,看起来我将ng-model设置为true,然后在$digest期间,ng-model根据复选框的状态设置:选中或取消选中.所以它更像是单向绑定:根据复选框状态绑定ng-model?

解决方法

只需使用ng-change而不是ng-click

这是一个DEMO

angularjs – 如何根据angular.js中的子复选框选择父复选框?

angularjs – 如何根据angular.js中的子复选框选择父复选框?

我最近一直在玩Angular.js并决定在选中父复选框后检查所有复选框,我已经使用ng-model和ng-checked指令完成了.

<div ng-app>
        <div ng-controller="Ctrl">
            <input type="checkBox" ng-model="parent"/> Select All<br/>
            <input type="checkBox" ng-model="child_1" ng-checked="parent" ng-click="getAllSelected()"/> First<br/>
            <input type="checkBox" ng-model="child_2" ng-checked="parent" ng-click="getAllSelected()"/> Second<br/>
            <input type="checkBox" ng-model="child_3" ng-checked="parent" ng-click="getAllSelected()"/> Three<br/>
            <input type="checkBox" ng-model="child_4" ng-checked="parent" ng-click="getAllSelected()"/> Four<br/>
            <input type="checkBox" ng-model="child_5" ng-checked="parent" ng-click="getAllSelected()"/> Five<br/>
        </div>
    </div>

现在,我正在尝试选中所有子复选框,一旦检查了所有子复选框但面临一些问题.

function Ctrl($scope) {
       $scope.getAllSelected = function () {
          var chkChild = document.querySelectorAll('input[ng-model^="child_"]').length;
          var chkChildChecked = document.querySelectorAll('input[ng-model^="child_"]:checked').length;
          if (chkChild === chkChildChecked) $scope.parent= true;
          else $scope.parent= false;
       }
    }

演示:http://jsfiddle.net/codef0rmer/QekpX/

我们可以使上面的代码更健壮吗?

解决方法

复选框中的ng-checked属性采用表达式.因此,您可以使用和/或条件给出表达式,如下所述,以便根据表达式进行检查.

<input type="checkBox" ng-checked="child_1 && child_2 && child_3 && child_4 && child_5" ng-model="parent"/> Select All<br/>

当单击每个子复选框时,您不必编写单独的函数来执行计算.

Here is example in jsfiddle

angularjs – 如果选中复选框,则调用具有true值的函数,如果未选中复选框,则调用false值

angularjs – 如果选中复选框,则调用具有true值的函数,如果未选中复选框,则调用false值

我有一个简单的复选框输入

<input type="checkBox" name="xxx" data-ng-clik='someFunction(true/false)' "/>

如果用户勾选复选框,我想用真值调用我的someFunction(true),如果用户取消选中,我想用false值调用相同的函数someFunction(false).

任何建议我怎么能这样做?

解决方法

您应该在ng-change of复选框上调用您的方法,以获得正确的更改值.还要添加ng-model以获得双向绑定,以启用复选框值.

<input ng-model="myCheckBox" type="checkBox" name="xxx" 
       ng-change='someFunction(myCheckBox)'">

关于根据laravel中复选框的选择计算总值layui获取复选框选中的值的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于android – 只选择一个启动首选项复选框的复选框、angularjs – angular复选框,使用ng-click重置绑定到复选框的ng-model,从而防止取消选中该复选框、angularjs – 如何根据angular.js中的子复选框选择父复选框?、angularjs – 如果选中复选框,则调用具有true值的函数,如果未选中复选框,则调用false值的相关信息,请在本站寻找。

本文标签: