【问题标题】:Radio button click event not firing for the first time in FirefoxFirefox 中第一次没有触发单选按钮单击事件
【发布时间】:2014-01-22 13:46:45
【问题描述】:

单选按钮点击事件不是第一次触发,而是在firefox中第二次点击触发,但它在IE,Chrome中运行良好:

if ($("#div-1").children().length == 1 && $("#div-1").find(':radio').length >= 1) {

    $("#done-button").hide();

    $("#div-1").find(':radio').on("click", function () {

        console.log("clicked");

        $("#done-button").click();

    });

}

【问题讨论】:

标签: javascript jquery


【解决方案1】:

您可以尝试使用:

$('input:radio') 

// or $("input[type='radio']")

来自jQuerydocs的建议

建议在:radio前加上标签名或其他 选择器;否则,将隐含通用选择器 ("*")。其他 换句话说,裸 $( ":radio" ) 等价于 $( " *:radio" ),所以 $( "input:radio" ) 应改为使用

【讨论】:

  • 这并没有解决主要问题,它是一个优化技巧。
  • 不工作!我也试过了..但无论如何代码在chrome中工作,即在firefox中没有
  • @user3222072 你用的是什么 jQuery 版本?你能创建一个fiddle 来复制你的问题吗?
  • @user3222072 那么所有浏览器都应该没问题,你能创建一个基本的小提琴吗,不需要完整的代码,只是相关的部分,所以我可以帮助你更多:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-13
  • 2011-07-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多