【发布时间】: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,而不是之前!委派可能是一种选择,但在您的情况下并不准确