2010-03-31 116 views
1

这个工作在jQuery的1.3.2,而不是在1.4选择在jQuery的1.4选择字段不工作

$("#container").children().map(function() { 
    var child = $(this); 

    if (child.is(":select")) { 
     //do something with child 
    } 
}); 

什么是jQuery的1.4这样做的正确方法?

+0

你使用的是jQuery 1.4.2吗? – 2010-03-31 12:21:45

+0

是的,它在1.4.2中不起作用 – Vnuk 2010-03-31 12:37:02

回答

0

如果你想选择的元素:

$("#container").children().map(function() { 
    var child = $(this); 

    if (child.is("select")) { 
     //do something with child 
    } 
}); 

儿童()不接受一个选择,所以你可以减少到:

$("#container").children('select').map(function() { 
    var child = $(this); 
    //do something with child 
}); 
+0

谢谢,还是不敢相信:是大不了的:) – Vnuk 2010-03-31 12:38:42

0

如果我理解正确的话,我会建议访问tagName(测试):

$("#container").children().map(function() { 
    var child = $(this); 

    if (child[0].tagName == "SELECT") { // or this.tagName == "SELECT" 
     //do something with child 
    } 
});