【问题标题】:Set td checked attribute设置 td 检查属性
【发布时间】:2013-12-20 16:10:17
【问题描述】:

我有一个包含多行的表格,每一行都有一个复选框:

<tr id="${user_id}" class="SearchAccount" style="height: 40px;">
    <td>John</td>
    <td>John</td>
    <td>Smith</td>
    <td>20/12/2013</td>
    <td>
        <div class="itoggle">
            <input type="checkbox" name='${user_id}' value="member" class="editteamtextbox" />
        </div>
    </td>
</tr>
<tr id="${user_id}" class="SearchAccount" style="height: 40px;">
    <td>Adam</td>
    <td>John</td>
    <td>Jones</td>
    <td>20/12/2013</td>
    <td>div class="itoggle">
        <input type="checkbox" name='${user_id}' value="member" class="editteamtextbox" />
        </div>
    </td>
</tr>

当复选框更改时,我在设置“已选中”时遇到问题: 我使用以下代码执行此操作:

$('.editteamtextbox').iToggle({
     easing: 'easeOutExpo',
     keepLabel: true,
     speed: 200,
     onClickOn: function () {
         $(this).closest('input').prop('checked', 'checked');
     },
     onClickOff: function () {
         $(this).closest('input').prop('checked', 'false');
     }
 });

【问题讨论】:

标签: javascript html


【解决方案1】:

如果你想每次点击 td 标签检查你的收音机,你可以这样做:

$(function(){
    $('td .itoggle').click(function(){
        if($(this).children("input[type=checkbox]").prop('checked')){
            $(this).children("input[type=checkbox]").prop('checked', false);
        }
        else{
            $(this).children("input[type=checkbox]").prop('checked', true);        
        }
    });
});

【讨论】:

  • 我认为 OP 是使用 iToggle 插件并且有问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-03-23
  • 2018-10-01
  • 2014-05-05
  • 2011-08-22
  • 2011-08-31
  • 2016-12-31
  • 1970-01-01
相关资源
最近更新 更多