Jquery帮助检查和取消标签点击
Jquery help check and uncheck on label click
我正在尝试创建一个选中和取消选中标签上的复选框的功能。
这是我的jsfield: http://jsfiddle.net/PTAFG/1/
不能修改HTML
我的HTML:
<div style="float: left; border: 1px solid rgb(255, 153, 0); width: 198px; margin-top: 2px; background: none repeat scroll 0% 0% rgb(255, 255, 255);">
<label style="float: left; width: 198px; background: url("../images/ulabel.png") repeat-x scroll 0% 0% transparent; height: 35px; margin: 0pt; position: relative;">
<span style="display: block; font-family: Helvetica; font-weight: bolder; margin-left: 20px; margin-top: 10px; font-size: 12px; width: 120px;">UBGRÆNSET TRAFIK</span>
<input type="hidden" value="0" name="search[php_is_true]"><input type="checkbox" value="1" style="position: absolute; right: 26px; top: 12px;" name="search[php_is_true]" id="search_php_is_true">
</label>
<label style="float: left; width: 198px; background: url("../images/ulabel.png") repeat-x scroll 0% 0% transparent; height: 35px; margin: 0pt; position: relative; border-top: 1px solid rgb(255, 153, 0); border-bottom: 1px solid rgb(255, 153, 0);">
<span style="display: block; font-family: Helvetica; font-weight: bolder; margin-left: 20px; margin-top: 10px; font-size: 12px; width: 120px;">UBGRÆNSET PLADS</span>
<input type="hidden" value="0" name="search[php_is_true]"><input type="checkbox" value="1" style="position: absolute; right: 26px; top: 12px;" name="search[php_is_true]" id="search_php_is_true">
</label>
<label style="float: left; width: 198px; background: url("../images/ulabel.png") repeat-x scroll 0% 0% transparent; height: 35px; margin: 0pt; position: relative;">
<span style="display: block; font-family: Helvetica; font-weight: bolder; margin-left: 20px; margin-top: 10px; font-size: 12px; width: 120px;">HJEMMESIDEPROGRAM</span>
<input type="hidden" value="0" name="search[php_is_true]"><input type="checkbox" value="1" style="position: absolute; right: 26px; top: 12px;" name="search[php_is_true]" id="search_php_is_true">
</label>
</div>
我Jquery: $(document).ready(function() {
$('div').click(
this.closest('input[type="checkbox"]').attr('checked', true);
});
$t.closest('.checkGroup').find('.payload').toggle( $t.is(':checked'));
if( !$t.is(':checked') ){
$t.closest('.checkGroup').find('.payload input[type="checkbox"]')
.attr('checked',false);
}
}).trigger('change');
});
您可以使用jQuery prop函数来更改复选框。代码应该是
$('label').bind('click',function(){
var input = $(this).find('input');
if(input.prop('checked')){
input.prop('checked',false);
}else{
input.prop('checked',true);
}
});
相关文章:
- 在<页眉>标签
- 如何在angularJS中编辑时,如果DB中的值为true,则设置复选框,如果值为false,则取消选中复选框
- jquery点击函数select&取消选择
- Ckeditor-plugin:插入虚假元素add不情愿<p>标签前后
- iframe正在添加标签,需要删除它们
- 使用Jquery选择或取消选择ListView中的所有复选框
- 如何自动调整标签的高度以适应内容
- 使用jquery选中/取消选中单个复选框
- Jquery标签插件粘贴问题
- Twitter引导程序Typeahead-Id&标签
- 使用javascript取消隐藏和隐藏表单中的某些元素
- 选中和取消选中不同的 td 标签
- 为什么使用替换来取消转义 html 标签也会去除所有其他 html 标签
- 取消选中带有标签的 html 复选框
- 在下钻中取消对xAxis标签的单击操作的绑定
- 如何取消选择一个简单的chrome扩展HTML按钮标签
- Jquery帮助检查和取消标签点击
- 如何在jquery中使用标签取消选中单选按钮
- Safari浏览器崩溃时,取消对焦和再次对焦标签用jquery代码网站
- 在引导中取消应用某些标签