-8
<li><a href="#">WSN</a>
      <ul>
      <li><input type="checkbox" id="value" value="wsn/qabala.php" onchange="getline();" onclick="boxclick(this,'qabala')" /> Qabala</li>
      <li><input type="checkbox" id="value" value="wsn/ismailli.php"  onchange="getline();" onclick="boxclick(this,'ismailli')" /> Ismayilli</li>
      <li><input type="checkbox" id="value"  value="wsn/agshu.php"  onchange="getline();" onclick="boxclick(this,'aghsu')" /> Aghsu</li>
      <li><input type="checkbox" id="value" value="wsn/shamakhi.php" onchange="getline();"  onclick="boxclick(this,'shamakhi')" /> Shamakhi</li>
      <li><input type="checkbox" id="value" value="wsn/shabran.php"  onchange="getline();" onclick="boxclick(this,'shabran')" /> Shabran</li>
      <li><input type="checkbox" id="value" value="wsn/siyazan.php"  onchange="getline();"  onclick="boxclick(this,'siyazan')" /> Siyazan</li>
      <li><input type="checkbox" id="value" value="wsn/jalilabad.php"   onchange="getline();" onclick="boxclick(this,'jalilabad')" /> Jalilabad</li>
      <li><input type="checkbox" id="value"  value="wsn/masalli.php" onchange="getline();"  onclick="boxclick(this,'masalli')" /> Masalli</li>
      <li><input type="checkbox" id="value" value="wsn/lerik.php" onchange="getline();"  onclick="boxclick(this,'lerik')" /> Lerik</li>
      <li><input type="checkbox" id="value" value="wsn/yardimli.php" onchange="getline();"  onclick="boxclick(this,'yardimli')" /> Yardimli</li>

      </ul>

我已经改变了。它有效,但我只得到第一个数据。为什么是这样?[只有wsn/qabala.php]

4

2 回答 2

3

如果您使用 id 调用,则 id 必须是唯一的

脚本

    <script type="text/javascript">
    function boxclick(checkvalue,str,chk)
    {
        var lfckv = document.getElementById(chk).checked
        alert(lfckv)
        alert(checkvalue);
        alert(str);
        if(lfckv)
        {
            //code on checked
        }
        else
        {
            //code on unchecked
        }

    }
</script>

html

<ul>
  <li><input type="checkbox" id="value1" value="wsn/qabala.php" onclick="boxclick(this.value,'qabala','value1')" /> Qabala</li>
  <li><input type="checkbox" id="value2" value="wsn/ismailli.php"  onclick="boxclick(this.value,'ismailli','value2')" /> Ismayilli</li>
  <li><input type="checkbox" id="value3"  value="wsn/agshu.php"   onclick="boxclick(this.value,'value3')" /> Aghsu</li>
  <li><input type="checkbox" id="value4" value="wsn/shamakhi.php"  onclick="boxclick(this.value,'shamakhi','value4')" /> Shamakhi</li>
  <li><input type="checkbox" id="value5" value="wsn/shabran.php"   onclick="boxclick(this.value,'shabran','value5')" /> Shabran</li>
  <li><input type="checkbox" id="value6" value="wsn/siyazan.php"    onclick="boxclick(this.value,'siyazan','value6')" /> Siyazan</li>
  <li><input type="checkbox" id="value7" value="wsn/jalilabad.php"   onclick="boxclick(this.value,'jalilabad','value7')" /> Jalilabad</li>
  <li><input type="checkbox" id="value8"  value="wsn/masalli.php"   onclick="boxclick(this.value,'masalli','value8')" /> Masalli</li>
  <li><input type="checkbox" id="value9" value="wsn/lerik.php"   onclick="boxclick(this.value,'lerik','value9')" /> Lerik</li>
  <li><input type="checkbox" id="value10" value="wsn/yardimli.php"   onclick="boxclick(this.value,'yardimli','value10')" /> Yardimli</li>

  </ul>

你可以用你提到的函数调用它

boxclick(this.value)

于 2013-05-01T12:31:36.960 回答
1

id 必须是唯一的,您才能引用该控件。

因为您所有的 ID 都是“价值”,所以它只是返回第一个。

于 2013-05-01T12:32:59.757 回答