Javascript 如何在 ie7 中使用 jquery 启用禁用的单选按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5641380/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 18:13:08  来源:igfitidea点击:

How do you enable a disabled radio button using jquery in ie7

javascriptjqueryhtmlinternet-explorer-7

提问by coder

This works in Firefox. How can I make it work in IE7?

这适用于 Firefox。我怎样才能让它在 IE7 中工作?

$( '#addressSection input:radio' ).attr( 'disabled', false );

I've also tried these to no avail:

我也试过这些无济于事:

$( '#addressSection input:radio' ).removeAttr( "disabled" );

$( '#addressSection input:radio' ).attr( 'disabled', 'false' );

$( '#addressSection input:radio' ).attr( {disabled: false} );

$( '#addressSection input:radio' ).attr( {disabled: 'false'} );

Here's the radio button html as it is rendered by IE7. The original is written in Spring and custom tags.

这是 IE7 呈现的​​单选按钮 html。原始是用 Spring 和自定义标签编写的。

<div id="addressSection">
  <div class="column">
    <ul class="simpleForm">
      <li>
        <input id="addressUseUorA" name="addressUseUorA" value="U" type="radio" type="text" value=""/>
        <label for="addressUseUorA">Use User Address</label>
        <input id="addressUseUorA" name="addressUseUorA" value="A" type="radio" type="text" value=""/>
        <label for="addressUseUorA">Use Account Address</label>
     </li>
   </ul>
 </div>
</div>

UPDATE:

更新:

Here's what was causing the issue.

这是导致问题的原因。

I disabled the field like this, trying to disable all fields in the DIV:

我禁用了这样的字段,试图禁用 DIV 中的所有字段:

$( '#addressSection' ).attr( 'disabled', true);

This causes an issue in ie7, but not firefox.

这会导致 ie7 出现问题,但不会导致 Firefox。

The issue was resolved when I changed the disable code to:

当我将禁用代码更改为:

$( '#addressSection input' ).attr( 'disabled', true);

my guess is that the disable attribute was applied to the div and not the field and so could not be removed by referencing the radio button.

我的猜测是禁用属性应用于 div 而不是字段,因此无法通过引用单选按钮删除。

Thanks for all of the help.

感谢所有的帮助。

回答by Naftali aka Neal

did you try:

你试过了吗:

$( '#addressSection input[type="radio"]' ).removeAttr( "disabled" );

回答by Kristoffer Lundberg

Try:

尝试:

$('#addressSection input[type=radio]').attr('disabled', false);

回答by Mohammed Swillam

I've just give it a test on JsFiddle and looks like removeAttris working just fine on chrome/FF/IE7.

我刚刚在 JsFiddle 上对其进行了测试,看起来removeAttr在 chrome/FF/IE7 上运行良好。

here is the live sample link: http://jsfiddle.net/2GpyQ/1/

这是实时示例链接:http: //jsfiddle.net/2GpyQ/1/

let me know if it worked for you, Thanks

让我知道它是否对你有用,谢谢

回答by Pavel

You need to use a different ID for input elements. This code is working:

您需要为输入元素使用不同的 ID。此代码正在工作:

<div id="addressSection"> <div class="column"> 
    <ul class="simpleForm"> 
        <li> 
            <form>
            <input id="addressUseUorA1" name="addressUseUorA" value="U" type="radio" type="text" disabled="disabled" value=""/> 
            <label for="addressUseUorA1">Use User Address</label> 
            <input id="addressUseUorA2" name="addressUseUorA" value="A" type="radio" type="text" value=""/> 
            <label for="addressUseUorA2">Use Account Address</label> 
            </form>
            <a href="#">click</a>
        </li> 
    </ul> 
</div> </div>
<script>
$('#addressSection a').click(function(e) {
    e.preventDefault()
    $( '#addressSection input[type="radio"]' ).removeAttr( "disabled" );
});
</script>