我正在测试表中的一行是否是第一个子项。到目前为止,我已经:
//the loop works
$( #GridFolderPopup ).find( tr ).each(function () {
if ( $(this).is(:first) == true ) //this is the faulty line
{
$(this).addClass( GridFolderRow );
};
});
有什么建议吗?
谢谢
我正在测试表中的一行是否是第一个子项。到目前为止,我已经:
//the loop works
$( #GridFolderPopup ).find( tr ).each(function () {
if ( $(this).is(:first) == true ) //this is the faulty line
{
$(this).addClass( GridFolderRow );
};
});
有什么建议吗?
谢谢
这可能是一个解决方案:
$( #GridFolderPopup tr:first ).addClass( GridFolderRow );
同时也大大减少了代码。
请尝试.is(:first)
而不是.is(:first)
。
您可能会混淆Javascript和Ruby:在Javascript中,冒号不能像这样使用(字符串之外)。
edit
Also, in your case :first-child
selector might be more appropriate. See the docs about the difference
http://api.jquery.com/first-child-selector/
http://api.jquery.com/first-selector/
简单地询问表
/tbody
的第一个子项比测试其中的每一行效率高得多。表越大,差异就越大。
因此:
如果您想“查看表中的[give]行是否是第一个子行”:
if ($(a_given_row).prev().length === 0) {
// no element before this row, so it s the first one.
}
如果要获取表的第一行:
// Directly ask the DOM for the first element child of the table/tbody
var firstRow = a_given_table.firstChild;
do {
firstRow = firstRow.nextSibling;
} while (firstRow.nodeType !== 1)
// If you don t need to support IE8-, you can use this single line instead:
var firstRow = a_given_table.firstChildElement;
请参阅此处的性能比较:http://jsperf.com/get-first-child-element
尝试以下代码
var allRows=$( #GridFolderPopup ).find( tr );
$.each(allRows,function(cntr,value){
if(cntr==0)
$(this).addClass( GridFolderRow );
});
$( #GridFolderPopup ).find( tr ).eq(0).addClass( GridFolderRow );
The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...
How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.
I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...
I have a div <div id="masterdiv"> which has several child <div>s. Example: <div id="masterdiv"> <div id="childdiv1" /> <div id="childdiv2" /> <div id="...
I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.
I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...
Ok, I m stumped. Basically, this script works fine in FF, but not in IE (6,7 or 8) - in which it returns an "Object doesn t support this property or method" error. Any ideas?: function ...
What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...