在 Firefox 5 中使用 jQuery 以编程方式选择单选按钮时遇到问题

发布于 2024-11-16 20:08:10 字数 714 浏览 5 评论 0原文

我正在尝试使用 jQuery 1.4.2 以编程方式选择单选按钮。它适用于 IE 8Chrome 12,但似乎不适用于 Firefox 5

单选按钮的 HTML 为:

<input type='radio' name='selected-row'>

我正在使用的代码如下,其中 radioButton 是一个 jQuery 对象。

    onCellSelect: function (rowid, iCol, cellcontent, e) {
        var cell = $(e.srcElement);
        var radioButton = cell.closest("tr").find("input[type='radio']");

        radioButton.click();
    }

我还尝试使用以下基于我在谷歌搜索中找到的内容的内容,该内容适用于 IE 和 Chrome,但不适用于 Firefox。

 radioButton.attr("checked", "true");
 radioButton.button("refresh");

如何让它在 Firefox 中运行?

I'm trying to programatically select a radio button using jQuery 1.4.2. It works in IE 8 and Chrome 12 but doesn't seem to work in Firefox 5.

The HTML for the radio button is:

<input type='radio' name='selected-row'>

The code I'm using is below, where radioButton is a jQuery object.

    onCellSelect: function (rowid, iCol, cellcontent, e) {
        var cell = $(e.srcElement);
        var radioButton = cell.closest("tr").find("input[type='radio']");

        radioButton.click();
    }

I've also tried using the below based on stuff I found googling and that works in both IE and Chrome, but not Firefox.

 radioButton.attr("checked", "true");
 radioButton.button("refresh");

How does one get this to work in Firefox?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绝影如岚 2024-11-23 20:08:10

与上面的 takeek 一样,以下内容在 Firefox 5 中有效

<input id="myRadioButton" type="radio" name="selected-row">

,并使用有效

$('#myRadioButton').attr('checked', true);

检查您的 radioButton 变量是否符合您的预期。您如何选择单选按钮?

另外 prop() 只在 1.6 中引入到 jQuery,所以 attr() 在这里就可以了。

Like takeek's above the following works in Firefox 5

<input id="myRadioButton" type="radio" name="selected-row">

and using works

$('#myRadioButton').attr('checked', true);

Check your radioButton variable is what you expect it to be. How are you selecting your radio button?

Also prop() was only introduced to jQuery in 1.6 so attr() is fine here.

‘画卷フ 2024-11-23 20:08:10
<input type="radio" value="The Answer" name="choices" id="myRadio">

-

$('#myRadio').attr('checked', true);

我在 Firefox 5 中工作得很好。我认为你的问题一定出在其他地方。也许是另一个特定于 Firefox 的错误阻止了它到达该行。

<input type="radio" value="The Answer" name="choices" id="myRadio">

-

$('#myRadio').attr('checked', true);

Works fine for me in Firefox 5. I think your problem must lie elsewhere. Maybe a different firefox-specific error is preventing it from reaching that line.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文