1. 程式人生 > >js 中選擇器呼叫元素

js 中選擇器呼叫元素

**********獲取父類 子類中某個元素

<table>
<tr>
<td>1</td><td>1</td><td>1</td>
</tr>
<tr>
<td>1</td><td>1</td><td>1</td>
</tr>
</table>

jquery:

$("tr:gt(0) td:not(:nth-child(1))").click(function(){
var obj=$(this);
var tt=obj.parent().children().eq(2);
})


一、jsp 中使用class="content"

$ ( " . content " ) 呼叫元素

二、jsp 中使用 id="content"

$ ( " # content " )呼叫元素

三、jsp 中匹配給定的屬性是某個特定值的元素

<input type="checkbox" name="newsletter" value="Hot Fuzz" />
<input type="checkbox" name="newsletter" value="Cold Fusion" />
<input type="checkbox" name="accept" value="Evil Plans" />
jquery:
$("input[name='newsletter']").attr("checked", true);

四、jsp 中含有給定屬性的元素

<div>
  <p>Hello!</p>
</div>
<div id="test2"></div>
jquery:
$("div[id]")
五、jsp 中匹配所有的單行文字框
<input type="text" />
jquery:
$(":text")
六、jsp 查詢每個元素的父元素
<div><p>Hello</p><p>Hello</p></div>
jquery:
$("p").parent()
<div><p>Hello</p></div><div class="selected"><p>Hello Again</p></div>
jquery:
$("p").parent(".selected")
七、jsp 查詢DIV中的每個子元素。
<p>Hello</p><div><span>Hello Again</span></div><p>And Again</p>
jquery:
$("div").children()
<div><span>Hello</span><p class="selected">Hello Again</p><p>And Again</p></div>
jquery:
$("div").children(".selected")
八、獲取匹配的第二個元素
<p> This is just a test.</p> <p> So is this</p>
jquery:
$("p").eq(1)

<p> This is just a test.</p> <p> So is this</p>
jquery:
$("p").eq(-2)