使用 JQuery,我需要编写一个函数,在单击两个按钮(edit0、edit1)中的任何一个时调用。我有以下代码:
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
$('[id^=edit]').click(function() {
alert("1111");
});
</script>
</head>
<body>
<button id="edit0" class="edit"> edit </button>
<button id="edit1" class="edit"> edit </button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我运行它时,单击按钮时没有任何反应。我尝试将脚本替换为:
$('button[class="edit"]').click(function() {
alert('1111');
});
Run Code Online (Sandbox Code Playgroud)
但结果是一样的。