首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >针对IE中单选按钮的jquery操作

针对IE中单选按钮的jquery操作
EN

Stack Overflow用户
提问于 2011-04-17 20:14:50
回答 2查看 1.8K关注 0票数 1

使用这里提出的方法-- http://www.techiegyan.com/2008/07/09/using-jquery-check-boxes-and-radio-buttons/

当选择“其他”单选按钮时,我想显示一个字段,否则就隐藏相同的字段。

该方法在非IE浏览器上工作正常,但在IE上工作(几乎)相反。看起来IE在取消选择选项时触发“更改”事件,而不是在选择选项时触发。

以下是html:

代码语言:javascript
复制
<div><label class="option" for="selection-1"><input type="radio" id="selection-1" name="submitted[selection]" value="10" checked="checked" class="form-radio"> 10</label></div>
<div><label class="option" for="selection-2"><input type="radio" id="selection-2" name="submitted[selection]" value="20" class="form-radio"> 20</label></div>
<div><label class="option" for="selection-3"><input type="radio" id="selection-3" name="submitted[selection]" value="50" class="form-radio"> 50</label></div>
<div><label class="option" for="selection-4"><input type="radio" id="selection-4" name="submitted[selection]" value="100" class="form-radio"> 100</label></div>
<div><label class="option" for="selection-5"><input type="radio" id="selection-5" name="submitted[selection]" value="0" class="form-radio">other</label></div>

<div id="other-selection-wrapper">
 <label for="other-selection">other:</label>
 <input type="text" maxlength="10" name="submitted[other_selection]" id="other-selection" size="10" value="" class="form-text">
</div>

以及脚本代码:

代码语言:javascript
复制
<script type="text/javascript">
$(document).ready(function(){
  $('#other-selection-wrapper').hide();

  $("input[@name='submitted[selection]']").change(function(){
    if ($("input[@name='submitted[selection]']:checked").val() == '0')
      { $('#other-selection-wrapper').show();   }
    else
      { $('#other-selection-wrapper').hide(); }
  });

});
</script>
EN

回答 2

Stack Overflow用户

发布于 2011-04-17 20:21:32

从你的例子网站上

,但我忘了提到,只有当您使用.click()而不是.change()

时,互联网开发者才能做到这一点

票数 1
EN

Stack Overflow用户

发布于 2011-04-17 20:42:51

为什么要将无线电组分配给html数组?Name=“选择”很好.

由此,您应该能够像这样显示/隐藏其他文本框:

代码语言:javascript
复制
<div>.....</div>
<div><label class="option" for="selection-5"><input type="radio" id="selection-5" name="selection" value="0" class="form-radio">other</label></div>

<div id="other-selection-wrapper">
    <label for="other-selection">other:</label>
    <input type="text" maxlength="10" name="submitted[other_selection]" id="other-selection" size="10" value="" class="form-text">
</div>

jquery:

代码语言:javascript
复制
$('input[name="selection"]:radio').click(function(){
    if($('input[name="selection"]:radio:checked').val() == 0){
        $('#selection-wrapper').css({'display':'block'});
    }else{
        $('#selection-wrapper').css({'display':'none'});
    }
});

未测

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5696146

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档