duanjiagu0655 2017-11-29 01:51
浏览 216

在同一行同时检查两个复选框

I know this question have already been answered in this link but what if i only want to check the checkbox beside the other checkbox.

just is like this

+-------------------------------+
|column1    | column2 |column3  |
+-------------------------------+
|check here |   ✓     |  ✓     |
+-------------------------------+
|butnothere |    □    |   □     |
+-------------------------------+

I've tried this function

$('#chk1, #chk2').on('click', function(){
    var checked = $(this).is(':checked');
    $('#chk1, #chk2').attr('checked', checked);
});

but it checks all of my checkboxes like this.

+-------------------------------+
|column1    | column2 |column3  |
+-------------------------------+
|check here |   ✓     |   ✓    |
+-------------------------------+
|butnothere |   ✓     |   ✓    |
+-------------------------------+

here is my html table(short copy).

<tr>
    <td width="20">
        <input id="chk1" type="checkbox">
        <input id="chk2" type="checkbox">
    </td>
</tr>

just like the one from above.

  • 写回答

3条回答 默认 最新

  • douwan4993 2017-11-29 01:58
    关注

    You can use SharedPreferences

    Below are the examples to set and get the value from shared preferences.

    1. Set the Value

      SharedPreferences.Editor editor = getSharedPreferences("Use your prefered name", MODE_PRIVATE).edit(); editor.putInt("val", 1); editor.apply();

    2. Get the Value

    To use shared preference in non-activity class, follow below steps

    1. Create static variable for context in your main activity.

      public static Context appContext;

    2. In onCreate method initialize the context

      public void onCreate() { appContext= getApplicationContext(); }

    3. Create getter method in same class.

      public static Context getAppContext(){ return appContext; }

    4. In your java class, you need to call below context method.

      Context applicationContext = MyActivity.getAppContext();

    5. Use PreferenceManager Class to get the SharedPreferences .

      SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(applicationContext); int val = prefs.getInt("val", 0); // where 0 is the default value.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?