0

我有一个链接到 jquery 页面的 html 页面,但无法正常工作。我正在使用 jquery 来查找单元格值低于 3000 的单元格,然后应该填充单元格,目前它不起作用。

这是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");
  }
});
4

3 回答 3

0

You seem to be selecting an ID (#d) in your javascript that doesn't exist in your HTML. You also have not linked the jQuery library to your code.

于 2012-10-23T15:22:21.280 回答
0

您需要将 jQuery 库添加到您的代码中:

<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="yourcode.js type='text/javascript></script>
</head>
于 2012-10-23T15:12:04.710 回答
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代码文件中。试试这个,如果你有其他问题再回来;)

当然,您可以直接链接到 googleapis,而不是直接链接到 jquery 的本地副本...

于 2012-10-23T15:14:55.427 回答