2012-10-23 27 views
0

我有一個鏈接到jquery頁面的html頁面,但無法讓它工作。我正在使用jquery來查找單元格值低於3000的單元格,然後填充單元格,它目前不起作用。javascript在html不工作

下面是HTML代碼

$(document).ready(function() { 
    rr(); 
})</script> 
</head> 
<body> 
<table class="colorMe"> 
<tr><td>2000</td><td>3500</td></tr> 
<tr><td>3000</td><td>2500</td></tr> 
<tr><td>4000</td><td>4500</td></tr> 
</table>​ 
</body> 
</html> 

and here is the jquery code which is on a seperate page 
// JavaScript Document 
$("#d td").each(function rr() { 
    var thisCell = $(this); 
    var cellValue = parseInt(thisCell.text()); 

    if (!isNaN(cellValue) && (cellValue <=3000)) { 
    thisCell.css("background-color","#FF0000"); 
    } 
}); 
+0

究竟是什麼意思「不工作」?你有任何錯誤信息?如何包括JavaScript?你有正確包含jquery嗎?你試過什麼了? – Christoph

+1

您不能同時使用'[src]'屬性和'

0

的正確用法是:

<head> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> 
<script src="yourcode.js" type="text/javascript"></script> 
<script type="text/javascript"> 
    $(document).ready(function() { 
     rr(); 
    }); 
</script> 
</head> 

和文件yourcode.js你的JavaScript代碼。試試這個,然後回來,如果您還有其他問題;)

當然,而不是你可以直接鏈接到的jQuery的本地副本googleapis ...

+0

我試過,但仍然沒有變紅。 – user1712552

+0

您是否使用了正確的選擇器?根據你的標記,它應該是'$(「。colorMe td」)'。 – Christoph

+0

是的,我試過 – user1712552

0

你似乎選擇ID( #d)在您的HTML中不存在的JavaScript中。您還沒有將jQuery庫鏈接到您的代碼。