我似乎無法得到checkbox.checked工作,我有一個腳本,更改基於onclick()的圖像,但我希望它根據是否複選框更改檢查與否。我究竟做錯了什麼?此外,如果有人也許能夠ADRESS此,複選框不IE8我無法獲得checkbox.checked工作
這裏檢查是不是活鏈接:http://jsbin.com/uburan/1/edit
代碼:
<script type="text/javascript">
function func()
{
var img1= document.getElementById("img1");
if(checkbox.checked)
{
img1.src = "images/" + "img1a.jpg";
img1.name = "off";
}
else
{
img1.src = "images/" + "img1.jpg";
img1.name = "on";
}
}
</script>
</head>
<body>
<form>
<p align="center">
<input type="checkbox" name="interest1" id="interest1" value="x">
<input type="checkbox" name="interest2" id="interest2" value="x">
<input type="checkbox" name="interest3" id="interest3" value="x"></p>
<p align="center">
<label for="interest1" id="label-interest1"><img src="images/img1.jpg" width="781" height="800" onclick="func()" id="img1" /></label>
<label for="interest2" id="label-interest2"><img src="/images/img2.jpg" width="781" height="800" /></label>
<label for="interest3" id="label-interest3"><img src="/images/img3.jpg" width="781" height="800" /></label></P><!-- code making checkbox be an image-->
</form>
「複選框」是不是有些神奇的變量會自動連上你的表格。您需要從DOM中定義它。 –
var checkbox = document.getElementById(「interest1」) – TryingToImprove