Javascript 单击“中的标记”按钮不起作用
我的html代码如下所示:Javascript 单击“中的标记”按钮不起作用,javascript,jquery,Javascript,Jquery,我的html代码如下所示: <button type="button" class="btn d-btn btnActor" style="background: #9cc447;" rel="tooltips" title="Militant" data-x = '1' data-y = '4' id='btn-matrice1'> <p style="color:#fdff36; font-size:10px;text-decoration:und
<button type="button" class="btn d-btn btnActor" style="background: #9cc447;" rel="tooltips" title="Militant" data-x = '1' data-y = '4' id='btn-matrice1'>
<p style="color:#fdff36; font-size:10px;text-decoration:underline;line-height:0px;padding-right:35px; padding-bottom:6px;"><a style="color:#fdff36;" class='list'>Liste</a></p>
<p style='color:#ffffff; font-size:10px; line-height:0px;'>Militant</p>
<p style="color:#ffffff; font-size:10px; line-height:0px;"> </p>
<p style="font-size:10px; line-height:0px; padding-left:35px;" class="count" data-count="1" mytag="1"></p>
</button>
当我单击时,它不工作。有人帮我修一下吗 您必须使用以下选项:
e.preventDefault();
试试这个
$(document).ready(function() {
$('document').on('click', 'a.list',function(e) {
alert(1);
});
});
请尝试以下代码:
$(document).ready(function() {
$("button").click(function(){
alert("button");
});
});
或
使用
ready()。这是根据法律规定的
从上面链接的jQuery文档:
事件处理程序仅绑定到当前选定的元素;他们
在代码调用.on()时页上必须存在。
要确保元素存在并且可以选择,请执行事件
在文档就绪处理程序中为
页面上的HTML标记
您可能将jQuery
放在页面顶部,在DOM中按钮“存在”之前
要修复此问题,请将jQuery
放在按钮下方(例如页面底部的
标记中),或者最好使用$(document.ready()
在a.list
之后缺少“
。假设它是一个打字错误,它工作正常:根据html5规范,标记无效。再次检查问题,我想有人编辑了它,“.”现在添加了引号。$('button')。on('click','a.list',function(e){e.preventDefault();});
$(document).ready(function() {
$("button").click(function(){
alert("button");
});
});
$(document).ready(function(){
$ ("button"). on ('click', function() {
alert(1);
});
});
$(document).ready(function() {
$('button').on('click', 'a.list', function (e) {
alert(1);
});
});