<html>
<head>
<script type="text/javascript" src="jquery-1.6.js"></script>
<script type="text/javascript">
//获取选中的checkbox的value值并且赋给文本框
function createOrder()
{
coffee=document.forms[0].coffee
txt=""
for (i=0;i<coffee.length;++ i)
{
if (coffee[i].checked)
{
txt=txt + coffee[i].value + " "
alert(coffee[i].checked);
}
}
document.getElementById("order").value="您订购的咖啡带有: " + txt
}
function check(){
}
//使用用拦截器拦截,判断value为1的,并且选中
function check2(){
$(":checkbox").each(
function(){
if($(this).val()=="1"){
$(this).attr("checked",true);
}
});
}
//使用拦截器拦截,并且循环判断是否选择。改变value值
function check3(){
$(":checkbox").each(
function(){
if($(this).attr("checked")=="checked"){
$(this).val("0");
}
alert($(this).attr("checked"));
});
}
function check4(){
}
</script>
</head>
<body>
<p>你要加什么呢?</p>
<form>
<input type="checkbox" name="coffee" value="1">加奶油<br />
<input type="checkbox" name="coffee" value="1">加糖块<br />
<input type="checkbox" name="coffee" value="1">加冰<br />
<input type="checkbox" id="woter" name="coffee" value="1">加水<br />
<br />
<input type="button" οnclick="createOrder()" value="发送">
<input type="button" οnclick="check()" value="OK">
<input type="button" οnclick="check2()" value="11111111">
<input type="button" οnclick="check3()" value="00000000">
<input type="button" οnclick="check4()" value="check4">
<br /><br />
<input type="text" id="order" size="50">
</form>
</body>
</html>
***********************************************
jquery 如何判断checkbox(复选框)是否被选中
在html 如果一个复选框被选中 是 checked=”checked”。
但是我们如果用jquery alert($(“#id”).attr(“checked”)) 会提示您是true而不是checked
所有可以用 if($(“#id”).attr(“checked”)==true)来判断就可以了