參考鏈接:https://blog.csdn.net/kkwant/article/details/82839269
https://blog.csdn.net/qq_35038153/article/details/78209353
1.JQuery this和$(this)的區別
// this其實是一個Html 元素。
// $this 只是個變量名,加$是為說明其是個jquery對象。
// 而$(this)是個轉換,將this表示的dom對象轉為jquery對象,這樣就可以使用jquery提供的方法操作。
<DOCTYPE html>
<head>
<style>
.a { display:none;
}
.a1 { color:gray;}
</style>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script>
function display_setting(item){
$(item).toggleClass("a1");
console.log("id:"+$(item).attr("id"));
op_name = $(item).attr("id"); //獲取id的方法1
o_name = item.id; //獲取id的方法2
console.log("o_name:"+o_name)
op_tr = "[name=" + op_name + "]";
$(op_tr).toggleClass("a");
}
</script>
<ul>
<li id="a" onclick="display_setting(this)">a</li>
</ul>
<table>
<tr name="a0"><td>a0</td><td>0</td></tr>
<tr name="a" class="a"><td>a</td><td>1</td></tr>
<tr name="a2"><td>a2</td><td>2</td></tr>
</table>
</body>
</html>