第七科灬水高
2016-10-31 12:43:12
我想實(shí)現(xiàn)的效果是:1.根據(jù)復(fù)選框的值來判斷按鈕是全喜歡或者全不喜歡。2.根據(jù)按鈕的value來控制復(fù)選框的全選或全不選<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>??? <title></title>??? <style type="text/css">??????? #Checkbox1??????? {??????????? width: 20px;??????? }??? </style></head><script>??? function a() {??????? var a = document.getElementsByName("ic");??????? for (var i = 0; i < a.length; i++) {??????????? a[i].checked = true;??????? }??????? b();??? }??? function b() {??????? var a = document.getElementsByName("ic");??????? var b = 0;??????? for (var i = 0; i < a.length; i++) {??????????? if (a[i].checked == true) {??????????????? ??????????????? b++;??????????? }??????? }??????????????? if (b == 4) {??????????????????? document.getElementById("Button1").onclick = function () { d(); };??????????????????? document.getElementById("Button1").value = "全不喜歡";??????????????? }??????????????? else { ??????????????? document.getElementById("Button1").onclick = function () { a(); };??????????????? document.getElementById("Button1").value = "全喜歡";??????????????? }??? }??? function d() {??????? var a = document.getElementsByName("ic");??????? for (var i = 0; i < a.length; i++) {??????????? a[i].checked = false;??????? }??????? document.getElementById("Button1").onclick = function () { a(); };??????? document.getElementById("Button1").value = "全喜歡";??? }</script><body>??? <p>??????? 你喜歡那種類型咖啡</p>??? <p>??????? <input name="ic" id="Checkbox1" type="checkbox" onclick="b()" />藍(lán)山咖啡</p>??? <p>??????? <input name="ic" id="Checkbox2" type="checkbox" onclick="b()" />摩卡</p>??? <p>??????? <input name="ic" id="Checkbox3" type="checkbox" onclick="b()" />拿鐵</p>??? <p>??????? <input name="ic" id="Checkbox4" type="checkbox" onclick="b()" />卡布奇諾</p>??? <p>??????? <input name="io" id="Button1" type="button" value="全喜歡"? onclick="a()"/></p></body></html>
3 回答


慕田峪3555374
TA貢獻(xiàn)137條經(jīng)驗(yàn) 獲得超18個(gè)贊
<html> <script?language=javascript> function?selectAll(){ var?a?=?document.getElementsByTagName("input"); if(a[0].checked){ for(var?i?=?0;i<a.length;i++){ if(a[i].type?==?"checkbox")?a[i].checked?=?false; } } else{ for(var?i?=?0;i<a.length;i++){ if(a[i].type?==?"checkbox")?a[i].checked?=?true; } } } </script> <input?type="checkbox"?value=1?/> <input?type="checkbox"?value=2?/> <input?type="checkbox"?value=3?/> <input?type="checkbox"?value=4?/> <input?type="checkbox"?value=5?/> <input?type="button"?name="select"?onclick="selectAll()"?value="全選/全不選"/> </html>
添加回答
舉報(bào)
0/150
提交
取消