我想问一下Jquery点击功能。" Enterbutton"是一个按钮可以点击功能。但我失败了。我错过了代码吗?
$(document).ready(function(){
$("Enterbutton").click(function(){
alert("The paragraph was clicked.");
我使用Jquery来编写交互代码。
答案 0 :(得分:0)
您需要修改选择器。
如果使用$('enterbutton')
,jQuery将查找此元素:
<enterbutton>...</enterbutton>
如果使用$('#enterbutton')
,jQuery将查找此元素:
<button id="enterbutton" type="button">...</button>
如果使用$('.enterbutton')
,jQuery将查找此元素:
<button class="enterbutton" type="button">...</button>
工作示例:
$(document).ready(function(){
$('enterbutton').click(function(){alert('The button with the type <enterbutton> was clicked.');});
$('#enterbutton').click(function(){alert('The button with id="enterbutton" was clicked.');});
$('.enterbutton').click(function(){alert('The button with class="enterbutton" was clicked.');});
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<enterbutton type="button">Click Enterbutton</enterbutton>
<button id="enterbutton" type="button">Click #enterbutton</button>
<button class="enterbutton" type="button">Click .enterbutton</button>
&#13;
NB 显然,不使用 <enterbutton>...</enterbutton>
- 这是无效的无意义标记。