English 中文(简体)
JQuery 挑选人和“is”问题
原标题:
  • 时间:2009-05-20 16:08:41
  •  标签:

我难以理解为什么某个特定选择者不为我工作。 诚然,我是一家新宝石。

这正确地选择了 首先。 div.edit Box on the page and Rainbows it Huang:

$( div.editbox:first ).css("background-color","yellow");

但是,如果......是,则该标的边境出现在each。 盒子是用过的。

$( div.editbox ).bind( mouseover , function(e) {
    if ($(this).is( div.editbox:first )) {$(this).css("border", "1px solid red");}
});

我尝试了各种变通办法,例如:一、二、四、一、二、三、四、五、四、五、四、五、四、五、四、五、四、五、四、五、四、五、五、四、五、四、五、四、五、五、五、五、五、六、五、五、六、五、六、六、六、十四、五、五、六、六、十四、五、六、十四、十四、五、十四、十四、十四、五、十四、十四、五、十四、十四、十四、十四、十四、五、十四、十四、五、十四、十四、十四、十四、十四、十四、十四、十四、十四、十四、五、十四、十四、十四、十四、十四、十四、十四、一、五、十四、十四、十四、十四、十四、十四、五、十四、十四、十四、十四、十四、十四、十四、十四、十四、十四、一、一、十四、十四、一、一、一、一、四、一、四、四、四、一、一、四、四、四、四

从根本上说,我希望能够可靠地检验这是否是同阶级名称相加的第一个或最后一个要素。

感谢!

Edit: 这里使用超文本Im:

<body>
<div class="container">
<p></p>
<div class="editbox" id="box1">Foo</div>
<div class="editbox" id="box2">Bar</div>
<div class="editbox" id="box3">Baz</div>
<div class="responsebox" id="rbox"></div>
</div>
</body>

这只是一个概念文件页;实际页数当然会更加复杂。 同样,如果我是在第一个或最后一个“div.edit箱”中,我想要可靠地检测什么。 我使用的是:

$( div.editbox:last ).addClass("lasteditbox");

然后测试if ((此处为......)is(上层盒)),这些仪器可操作,但似乎有条不紊,I m试图学习与JQuery做这件事的适当方法。

最佳回答

<><>UPDATE: 这是第一个要素。

$( div.editbox ).bind( mouseover , function(e) {
 if ($("div.editBox").index(this) == 0) {
      $(this).css("border", "1px solid red");
    }
});

就最后一项内容而言,该选择人的工作是:

if($("div.editBox").index(this) == ($("div.editBox").length-1)){
     $(this).css("color","red");
}
问题回答

如果你只想在四舍五入的那类洗衣箱中首先出现 mo。

$( div.editbox:first ).mouseover(function() {
   $(this).css("border", "1px solid red");
});

<><>Edit>/strong>

$( div.editbox ).mouseover(function() {
   $(this).css("border", "1px solid yellow");
}).filter( :first ).mouseover(function(){
  $(this).css("border", "1px solid red");
}).filter( :last ).mouseover(function(){
  $(this).css("border", "1px solid blue");
})

tried

if ($(this).is( :first )) {$(this).css("border", "1px solid red");}
    $( div.editbox ).mouseover(function() {
       //change the css for all the elements
       $(this).css("background-color", "yellow");
    })
    .filter( :first,:last ).mouseover(function(){
      //execlude the first and the last
      $(this).css("background-color", "Blue");
    })




相关问题
热门标签