首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

JQuery JS 有关问题

2012-04-30 
JQuery JS 问题不知道这样的选择器如何表达 望各位高手给解答下$(#companies tbody tr)这样选择了compan

JQuery JS 问题
不知道这样的选择器如何表达 望各位高手给解答下

$("#companies tbody tr")这样选择了companies 中 tbody的每一行,假设tr中有多个<td>如下:

<table id="companies" class="display">
 <tbody>
  <tr rel="0">
  <td><input type="checkbox" style="margin:left" /></td>
  <td>Emkay Entertainments</td>
  <td>Nobel House, Regent Centre</td>
  <td>Lothian</td>
  </tr>
 </tbody>
<table>

我现在还是想选择<tr>这样的一行但是不想选这一行中的第一个<td>元素, 不知道该怎么表达了。。。

[解决办法]

JScript code
$(function(){    $("#companies tbody tr td").each(function(i){          alert($(this).text());   });});
[解决办法]
JScript code
            $("#companies tbody tr td:not(:first)").click(function(){                alert($(this).html())            })
[解决办法]
HTML code
<html xmlns="http://www.w3.org/1999/xhtml"><head>    <title>无标题页</title>    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>    <script type="text/javascript">       $(document).ready(function(){            $("#companies tr").each(function(){                $(this).find("td").not(":first").click(function(){                    alert($(this).html())                })                })       })    </script></head><body><table id="companies" class="display"> <tbody>  <tr rel="0">  <td><input type="checkbox" style="margin:left" /></td>  <td>Emkay Entertainments</td>  <td>Nobel House, Regent Centre</td>  <td>Lothian</td>  </tr>  <tr rel="0">  <td><input type="checkbox" style="margin:left" /></td>  <td>Emkay Entertainments</td>  <td>Nobel House, Regent Centre</td>  <td>Lothian</td>  </tr> </tbody></table></body></html>
[解决办法]
探讨

HTML code
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题页</title>
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
……

[解决办法]
$(document).ready(function(){
$("#companies tr").each(function(){
$(this).find("td").not(":first").click(function(){
alert($(this).html())
})
})
})
[解决办法]
你想获取哪个td 都行 前提你要给指定的td 加一个样式名 
譬如 定义一个叫SName样式名
 <table id="companies" class="display">
<tbody>
<tr rel="0">
<td><input type="checkbox" style="margin:left" /></td>
<td class="SName">Emkay Entertainments</td>
<td>Nobel House, Regent Centre</td>


<td>Lothian</td>
</tr>
</tbody>
<table>

$(function(){
$("#companies tbody tr ").each(function(i){
alert($(this).find(".SName").text()); 
});
});

热点排行