大家好,我有 3 个按钮,一个在工作,其他人不能告诉我原因.. 在 jquery 中,我命令它隐藏其中有 # 的 id,但中间按钮在工作,它有 2 个 id,其中一个带有 # 和一个没有我把一个没有# 带走它不起作用..我是编程新手。对不起我的英语
<样式>
button.rond { width:50px;高度:50px;
/style>
<正文> <表id="t01"style="width:750px">
< td>Coo< /td>
< td>Fin< /td> < td> < button class="rond" id="#panel6">Stop< /button>< /td>
< td>Coo< /td>
< td>Euro< /td>< td>< button class="rond" id="#panel7">Stop< /button>< /td>
< tr id="#panel8">
< td>Coo< /td>
< td>Fin< /td> < td><button class="rond">Stop< /button>< /td>
/tr> 表> < script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"> </script>
<脚本>
$(函数(){
$('.rond').on('点击',function(){
var id =$(this).attr('id');
$(id).hide(1);
});
});
/脚本>
/表格>
/正文>
最佳答案
您可以通过this.id
获取id,您还需要在id选择器前添加#
。但是这里不需要获取id,直接使用$(this)
即可。这里的this
指的是被点击的dom元素。
$(function(){
$('.rond').on('click',function(){
$(this).hide();
});
});
关于jquery - id 不工作使用 jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32298214/