我有一個表有很多td。當我點擊按鈕時,我想要一個td中的一些html元素。如何使用「this」解決此功能?「這個」功能不能正常工作
$(document).ready(function() {
$("button").click(function clickMe(e) {
$(this).html ("this is hai")
});
});
table td {
border: 1px solid;
border-color: lightgray;
overflow:hidden;
height:17px;
/*max-height:10px;*/
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<body>
<table style="border-collapse:collapse;border:1px solid;width:10%;height:100px;margin-top:50px;">
<tr>
<td id="container"onclick="clickMe(this)"></td>
<td></td>
<td></td>
</tr>
</table>
<button id="container" > clickme</button>
</body>
</html>
** 1。** ID應該是唯一的。 ** 2。**''clickMe'是_local_到'ready()'。 ** 3。** .html(' – Tushar
也應該沒有空格,一旦你改變你的id類(這將是更可取的),那麼你可以在jquery $('。container')中使用。 ('click',function clickMe(e){...});並從html中刪除onclick。 –
請給我一個完美的腳本使用此 –