我现在想用jquery来设置chekbox的值,就是我点击那个框设置他的值为1,在点下(即对号取消)让他的值为0,我写的如下,但有问题,请问如何改,或写!
<script> $("#document").ready(function(){
$("#sfqy").click(function(){
if($(this).attr("checked")){
$(this).removeAttr("checked");
$(this).val("0");
alert($(this).val());
}
else{
$(this).attr("checked",'true');
$(this).val("1");
alert($(this).val());
} }) })
</script>下面是我的checkbox及属性
<td>
<label><input type="checkbox" id="sfqy" name="news.SFQY" value="嘿嘿">是否启用</label>
</td>
<script> $("#document").ready(function(){
$("#sfqy").click(function(){
if($(this).attr("checked")){
$(this).removeAttr("checked");
$(this).val("0");
alert($(this).val());
}
else{
$(this).attr("checked",'true');
$(this).val("1");
alert($(this).val());
} }) })
</script>下面是我的checkbox及属性
<td>
<label><input type="checkbox" id="sfqy" name="news.SFQY" value="嘿嘿">是否启用</label>
</td>
解决方案 »
- 困扰了很久的问题了:The server encountered an internal error () that prevented it from...
- 有没有点击input type=text可以弹出窗口的东西,最好是jquery的
- strust2.0与fckeditor整合问题
- FCKeditor HTML 在线编辑器 JAVA 版 使用小记
- 做好的applet怎么才能在页面上显示,我这老提示“class文件找不到”
- 在jsp 中串操作?
- 在新窗口打开此页怎样实现?我正在做一个个人网站,需要大家帮忙!
- javamail测试帐号问题
- 为什麽servlet页面不能显示?页面显示404错误
- 字符串数组比较?报错!请高手指教!在线,jijiji
- 如何用jsp将文件上传至http文件服务器
- Ext FormPanel添加组件问题
$("#employment_present").attr("checked",true);
} else{$("#id").attr("checked",false);}
if(c){
$("#sfqy").val("1");
alert($("#sfqy").val());
}
else{
$("#sfqy").val("0");
alert($("#sfqy").val());
}
})
这么做就对了