【问题标题】:jquery click on radio button not workingjquery单击单选按钮不起作用
【发布时间】:2013-12-27 18:53:40
【问题描述】:

我有一个 HTML 页面,如下所示:

<html>
<head>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</head>

<script>
$("input:radio[name=aa]").click(function() {
window.location.href="http://www.google.com";
});

function get_search_results(params) {
    alert('sdsds');
}
</script>
<body>
<input type="radio" name="aa" />AA
<input type="radio" name="aa" />AB
<input type="radio" name="aa" />AC
</body>
</html>

所以我期待每当我点击三个单选按钮中的任何一个时,它都应该重定向到google。但它什么也没做!为什么?

【问题讨论】:

  • 在文档就绪处理程序中包装代码或声明处理程序 AFTER 元素已添加到 DOM,而不是之前!委派可能是一种选择,但在您的情况下并不准确

标签: jquery click radio


【解决方案1】:

文件加载时需要执行脚本:

$(document).ready(function(){
    $("input:radio[name=aa]").click(function() {
        window.location.href="http://www.google.com";
    });
});

【讨论】:

  • @SurajHazarika 很高兴我能帮上忙。
猜你喜欢
  • 2018-05-02
  • 1970-01-01
  • 2017-03-09
  • 2017-05-23
  • 1970-01-01
  • 2018-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多