我在一个MVC站点的视图中有这行代码,它在一个ForEach循环中,该循环在传递给视图的模型中迭代一组时间。
<li data-cft-times="true" class="selectedList">@times.time
<input type="checkbox" class="ficoEntry" checked="checked" data-cft-time="true" />
</li>然后,在我的Jquery中,我尝试查看用户是否更改了复选框以取消选择某个时间,我目前有这样的设置,但它返回所有时间,而不仅仅是那些仍然具有复选框的时间。
if ($('input[data-cft-time]').attr("checked") == "checked") {
//do stuff...
}有没有人知道我错在哪里,因为我已经尝试了很多次,但似乎一无所获,但我知道这是一个让我陷入困境的简单问题……
谢谢。
编辑...
我已经尝试了下面的两个帖子,但都不起作用。当我取消选中复选框时,看起来DOM没有更新,因为使用F12的HTML代码仍然显示以下内容
<input type="checkbox" class="ficoEntry" checked="checked" data-cft-time="true" />我是不是漏掉了什么.
更多信息..
<ul>
<li class="selectedList" data-cft-times="true">2300
<input class="ficoEntry" type="checkbox" checked="checked" data-cft-time="true">
</li>
<li class="selectedList" data-cft-times="true">0000
<input class="ficoEntry" type="checkbox" checked="checked" data-cft-time="true">
</li>
<li class="selectedList" data-cft-times="true">0100
<input class="ficoEntry" type="checkbox" checked="checked" data-cft-time="true">
</li>
<li class="selectedList" data-cft-times="true">0200
<input class="ficoEntry" type="checkbox" checked="checked" data-cft-time="true">
</li>
</ul>这是当前的JQuery。
$("li[data-cft-times]").each(function (index) {
text = $(this).text().slice(0, 4);
if ($('input[data-cft-time]').is(':checked')) {
time += "{\"time\":\"" + text + "\"},";
}
});发布于 2014-01-10 04:11:05
试试这个:
if($('input[data-cft-time]').is(':checked')){
}https://stackoverflow.com/questions/21030094
复制相似问题