【问题标题】:jquery wont preload radio buttons in IE 7jquery 不会在 IE 7 中预加载单选按钮
【发布时间】:2012-04-22 19:26:46
【问题描述】:

我正在尝试使用从 jquery AJAX 调用中检索到的数据预填充表单。数据正常,但在使用 IE 7 时我无法检查正确的单选按钮。

以下代码在 Firefox、Safari 和 Chrome 中运行良好

Lets assume data.description = 'student'

// I have tried both of these with no luck in IE 7
$("input[value='"+data.description+"']").attr('checked', true);
$("input[name='self_description']").filter("[value='"+data.description+"']").attr('checked', true);

<div><label><input type="radio" name="description" value="student">student</label></div>
<div><label><input type="radio" name="description" value="part time">part-time</label></div>

【问题讨论】:

    标签: jquery internet-explorer input radio-button


    【解决方案1】:

    您的过滤器表达式似乎缺少一个左方括号,应该引用文字。试试:

    $("input[name='self_description']").filter("[value='"+data.description+"']").attr('checked', true);
    

    编辑:

    唯一想到的另一件事是在 DOM 准备好后执行它:

    $(document).ready(function () {
        // your code here
    });
    

    【讨论】:

    • jquery 在一个通过 document.ready 调用的函数中
    • @peledies - 你试过正确引用data.description吗? .filter("[value='"+data.description+"']")
    • 好建议,但这并不能解决问题。我应该指出,这种方法适用于复选框。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-29
    • 2011-05-22
    • 1970-01-01
    • 2018-08-20
    • 2015-03-04
    • 1970-01-01
    相关资源
    最近更新 更多