2

i have form to send data to other page like:

<input name="ShowBuy" id="ShowBuy" type="radio" value="1" checked = "checked"> Show Buy
<input name="ShowBuy" id="ShowBuy" type="radio" value="0"> Hide Buy <br>
<input name="ShowSale" id="ShowSale" type="radio" value="1" checked = "checked"> Show Sale
<input name="ShowSale" id="ShowSale" type="radio" value="0"> Hide Sale<br>

when i checked Hide Buy and print the result, it show value "1" !!! why, it must show me value "0" . there are code to send :

<script language="JavaScript">
  $(function(){
           $('#Normal').click(function(){
               sessionStorage.ShowSale = $("#ShowSale").val();
               sessionStorage.ShowBuy = $("#ShowBuy").val();
              window.open('Print.php', '_blank')  
           }); 
       });   
</script>

where problem here.

4

1 回答 1

0

jquery 代码的问题在于您使用的是 ID 选择器,ID 应该是一个元素的唯一标识符,jquery 将匹配具有该 id 的第一个元素并返回值

这是一个解决方案:

<input name="ShowBuy" class="ShowBuy" type="radio" value="1" checked = "checked"> Show Buy
<input name="ShowBuy" class="ShowBuy" type="radio" value="0"> Hide Buy <br>
<input name="ShowSale" class="ShowSale" type="radio" value="1" checked = "checked"> Show Sale
<input name="ShowSale" class="ShowSale" type="radio" value="0"> Hide Sale<br>

上面我已将id属性替换为class

然后你需要改变你的jquery:

<script language="JavaScript">
  $(function(){
           $('#Normal').click(function(){
               sessionStorage.ShowSale = $("input.ShowSale:checked").val();
               sessionStorage.ShowBuy = $("input.ShowBuy:checked").val();
              window.open('Print.php', '_blank')  
           }); 
       });   
</script>

现在选择一个输入class="ShowBuy"并检查并获取值

于 2012-12-22T10:29:17.990 回答