我現在抓到了td1,我想把裡面的內容修改成 “Guanyu”;
下面是我寫的代碼,但是不好使
<html>
<head>
<script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
</head>
<body>
<table id="thisTable">
<tr>
<td>id</td>
<td>name</td>
<td>sex</td>
</tr>
<tr>
<td>001</td>
<td>Xiaoming</td>
<td>man</td>
</tr>
<tr>
<td>002</td>
<td>Laowang</td>
<td>man</td>
</tr>
<tr>
<td>003</td>
<td>Yan</td>
<td>Felman</td>
</tr>
</table>
</body>
<script>
$(function(){
var thisTable = $("#thisTable");
var tr = $("#thisTable tr");
var td_1 = tr.find("td:eq(1)");
td_1.each(function(){
if($(this).text()!="name"){
$(this).text()="Guanyu";
}
});
});
</script>
</html>
賦值語法錯了
$(this).text()="Guanyu";//這不是jq的賦值
//應該是這樣
$(this).text("Guanyu");