突然想到,請教一下這種問題怎么解決?
<!DOCTYPE?HTML> <html> ????<head> ????????<meta?http-equiv="Content-Type"?content="text/html;?charset=gb2312"> ????????<title>無標題文檔</title> ????</head> ???? ????<body> ????????<form> ??????????請選擇你愛好:<br> ??????????<input?type="checkbox"?name="hobby"?id="hobby1">??音樂 ??????????<input?type="checkbox"?name="hobby"?id="hobby2">??登山 ??????????<input?type="checkbox"?name="hobby"?id="hobby3">??游泳 ??????????<input?type="checkbox"?name="hobby"?id="hobby4">??閱讀 ??????????<input?type="checkbox"?name="hobby"?id="hobby5">??打球 ??????????<input?type="checkbox"?name="hobby"?id="hobby6">??跑步?<br> ??????????<input?type="button"?value?=?"全選"?onclick?=?"checkall();"> ??????????<input?type="button"?value?=?"全不選"?onclick?=?"clearall();"> ??????????<p>請輸入您要選擇愛好的序號,序號為1-6:</p> ??????????<input?id="wb"?name="wb"?type="text"?> ??????????<input?name="ok"?type="button"?value="確定"?onclick?=?"checkone();"> ????????</form> ????????<script?type="text/javascript"> ????????function?checkall(){ ????????????var?hobby?=?document.getElementsByTagName("input"); ??????????? ????????for(var?i=0;i<hobby.length;i++)??//?任務1? ???????????{hobby[i].checked=true;} ????????} ????????function?clearall(){ ????????????var?hobby?=?document.getElementsByName("hobby"); ???????????? ?????????for(i=0;i<hobby.length;i++)//?任務2???? ????????????{hobby[i].checked=false;} ????????} ???????? ????????function?checkone(){ ????????????clearall(); ????????????var?hobby=document.getElementsByName("hobby") ????????????var?j=document.getElementById("wb").value; ????????????for(var?i=0;i<j.length;i++){ ????????????if(parseInt(j)>6||parseInt(j)<1){ ????????????????alert("超過范圍!"); ????????????????document.getElementById("wb").value=""; ????????????} ????????????else{hobby[parseInt(j)-1].checked=true; ????????} ????????} ????????} ???????? ????????</script> ????</body> </html>
我的問題是:
在input中輸入1,確認后對應的第1個選項框會被選擇;但是如果我不刪除1,在1后加一個2,確定后第2個選項框也會被勾上.但是這應該是有問題的.input中的數字是12>6.
2015-07-30
?我在chrome和ie11下都測試了,你說的情況沒有發生.