如果我把我的jQuery放在沒有$(document).ready(function()的body的末尾,它可以正常工作,如果我使用$(document ).ready(function(),它不再起作用,我意識到當我將jQuery放置在頭部時,我需要function(),但是當我嘗試自己實現它時,沒有骰子,我盯着它太長時間,我沒有看到這個問題。jQuery不在頭部,但在身體確定
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#testTable tr").hover(
function(){$(this).addClass("highlighted");},
function(){$(this).removeClass("highlighted");}
);
});
</script>
<style type='text/css'>
.tablerow {background-color:yellow;}
.tableheader {background-color:Pink;}
.highlighted {background-color:Green;}
</style>
</head>
<body>
<table id="testTable">
<thead class="tableheader">
<tr><th>No</th><th>Name</th><th>Age</th><th>Salary</th></tr>
</thead>
<tbody id="testBody">
<tr class="tablerow"><td>1</td><td>Yong Mook Kim</td><td>28</td><td>$100,000</td></tr>
<tr class="tablerow"><td>2</td><td>Low Yin Fong</td><td>29</td><td>$90,000</td></tr>
</tbody>
</table>
</body>
,準確的HTML似乎爲我 –
工作什麼是「不工作」?文檔是什麼樣e你會得到什麼錯誤? – kennypu
我假設你在你的標記中有''標記? – VisioN