(JQuery)'table.class'不会'不工作,我可以'我不知道为什么.它还选择
(JQuery) 'table.class' doesn't work and i can't figure out why. It selects tables with other classes too
我的代码几乎是不言自明的。请看一下:
<html>
<body>
<!-- importing the latest jquery (1.6.4) here -->
<table class="notThisOne" cellspacing="0" cellpadding="0" border="0" style="width: 100%; height: 20px;">
<colgroup>
<col>
</colgroup>
<tbody>
<tr class="not">
<td>
</td>
<td>
<b>Nicholas O'Reilly</b>
</td>
<td></td>
<td>nikoreilly@hotmail.com </td>
<td></td>
</tr>
<tr class="not">
<td>
</td>
<td>
<b>John Smith</b>
</td>
<td></td>
<td>jsmithjr@gmail.com </td>
<td></td>
</tr>
</tbody>
</table>
<table class="contactListRow" cellspacing="0" cellpadding="0" border="0" style="width: 100%; height: 20px;">
<colgroup>
<col>
</colgroup>
<tbody>
<tr class="contactListRow">
<td>
</td>
<td>
<b>Nicholas O'Reilly</b>
</td>
<td></td>
<td>nikoreilly@hotmail.com </td>
<td></td>
</tr>
<tr class="contactListRow">
<td>
</td>
<td>
<b>John Smith</b>
</td>
<td></td>
<td>jsmithjr@gmail.com </td>
<td></td>
</tr>
</tbody>
</table>
<br><br>
<script type="text/javascript">
$('table.contactListRow').each(function(i) {
$name = "";
$email = "";
$('td').each(function(ii) {
$col = ii%5;
if( $col == 1){
$name = $(this).text();
}
if( $col == 3){
$email = $(this).text();
}
if( $col == 4){
//$(this).html('<a href="javascript: openwindow(''https://mail.google.com/mail/?view=cm&fs=1&tf=1&to="'+$name+'" <'+$email+'>'')">Email</a>');
$(this).text(i+"_"+ii);
}
});
});
</script>
</body>
</html>
问题是,任何表都会被更改,即使类不是指定的类。
怎么了?
提前谢谢。
附言:我只需要它在Firefox 6+上运行(仅供个人使用(。
更改此行
$('td').each(function(ii) {
至
$(this).find('td').each(function(ii) {
您的问题就在这里:
$('td').each(function(ii) {
$('td')
选择所有表格单元格,无论它们是否在您想要的表格中。因此,你并没有完全改变每个表,就像你(意外地(改变了每个表单元格一样。
请尝试使用$(this).find('td')
,这样会将表单元格选择器限制在您感兴趣的表中。
$('td').each(function(ii)
这不会改变每个td元素吗?
也许更像
xxxxx
无论如何,我还没有做太多的jScript,我的解决方案可能是不对的。
问题是您正在选择所有<td>
元素,其中包含以下行:
$('td').each(function(ii) {
相反,您可以使用find
在已经选择的表中查找,如下所示:
$(this).find('td').each(function(ii) {
(或者,要选择属于指定类的表的所有<td>
元素,可以说$('table.contactListRow td').each(function(ii) {
。(
相关文章:
- 我不知道我的编码有什么问题.(JavaScript)
- 单选按钮验证:我可以验证它,但我不知道原因
- 可以'我不知道如何使用谷歌图表API显示2个表
- 可以'我不知道李是在徘徊
- 可以'我不知道为什么这个数字赢了;t增量
- 可以'我不知道如何使用jQuery表单和.length
- 可以'我不知道如何根据日期自动显示文本内容
- JavaScript 错误:未捕获的类型错误:undefined 不是第 4 行的函数;我不知道我做错了什么
- 有人可以用javascript解释以下代码吗?它用于读取文本文件,但我不知道XML和AJAX的东西
- N00B 帮助 - 用于检查输入是否可以形成直角三角形的脚本.搞砸了我的警报,不知道我是否有变量
- 我的javascript函数没有'似乎不起作用.我可以'我不知道为什么
- 可以'我不知道如何正确放大整个网页
- 我有一个php文件,里面的代码中有一个错误,我可以'我不知道怎么修?以及将其余代码添加到何处
- 我可以'I don’我不知道我在做什么;m缺失,除了一个选项外,代码可以100%工作
- 循环学习.我不知道我的代码中缺少了什么
- 我的javascript输出与预期输出不匹配.我没有'I don’我不知道我哪里错了
- 试图修复一个Javascript倒计时.我不知道我在做什么
- jQuery在html中不起作用,我不知道我做错了什么
- 如果我不知道我将返回什么,我如何整齐地输出json对象中的所有数据?
- 模态中的角度.可以'我不知道我的控制器出了什么问题