悬赏分:20 该问题已到期 浏览:411 次

有一个问题想问一下,就是比如我市场报价填写了一个9,下面的区间报价就会自动
去选中对应的那就是5-10的那个,我想通过JS来实现,请高手赐教!谢谢!
|
试试这个,在文本框里输入数字,文本框失去焦点时会自动选中对应的单选框:
========================================== <html> <body> <input type="text" name="txtPrice" value="" maxlength="2" onblur="checkradio(this)" /> <br /> <input type="radio" name="rdoPrice" value="0-9" /> 0- 9 <input type="radio" name="rdoPrice" value="10-19" />10-19 <input type="radio" name="rdoPrice" value="20-29" />20-29 <input type="radio" name="rdoPrice" value="30-39" />30-39 <input type="radio" name="rdoPrice" value="40-49" />40-49<br /> <input type="radio" name="rdoPrice" value="50-59" />50-59 <input type="radio" name="rdoPrice" value="60-69" />60-69 <input type="radio" name="rdoPrice" value="70-79" />70-79 <input type="radio" name="rdoPrice" value="80-89" />80-89 <input type="radio" name="rdoPrice" value="90-99" />90-99 <script type="text/javascript"> function checkradio(obj){ var price=parseInt(obj.value,10); if(isNaN(price)){return;} var radiogroup=document.getElementsByName("rdoPrice"); for(var i=0;i<radiogroup.length;i++){ if(price>radiogroup[i].value.split("-")[0] && price<radiogroup[i].value.split("-")[1]){ radiogroup[i].checked=true; break; } } } </script> </body> </html> |
|
2个月前 smallpig0 : 你好,但是我的是服务器端控件,也是一样的可以吗? |
|
2个月前 丁学 : 服务器端控件也是一样的,只要单选按钮的名称能够确定就行了,JS里只用到了radio的name:rdoPrice 另外就是那个value要写对了,或者你可以使用其他的方式来实现,不过原理都一样,都是取得输入的数,然后遍历radio,选中应该选的 |