English 中文(简体)
如果父母有身份证,进行验尸检查
原标题:Jquery check if parent has an ID
  • 时间:2010-08-23 12:51:59
  •  标签:
  • jquery

试图检查父母是否包含有身份证的人

我的名单上

<ul>
<li></li>
<li id="selected">
    <ul>
        <li></li>
        <li></li>
    </ul>
</li>
<li></li>
</ul>

不知道如何在这里提出一个正确的清单?

if (jQuery(LiElement).parent("#selected"))
{
    //If parent has id=selected
}
else
{
    //If parent dont have id=selected
}

谁能帮助我?

问题回答

您可测试<代码>length property of the .0000 (“#s selected”):

if( Query(LiElement).parent("#selected").length ) 

如果母有<代码>#s selected ID将退回1(true),否则将0(false)。

<>注:你只检测直系亲属。 我想这是你想要的。

如果该身份证不是直系母,你可使用<编码>closest()测试该身份证的任何祖先。

if( Query(LiElement).closest("#selected").length ) 

更清楚的是,这也将测试目前<><>>的内容。

$( li ).each(function() {
    if ($(this).parent( #selected ).length) {
    ⋮
    } else {
    ⋮
    }
});

这对我来说是巨大的。

不是正面的,但我认为这应该只是实事求是的。

if ($( li ).parents( #selected )) {...} else {...}




相关问题
getGridParam is not a function

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 )...

selected text in iframe

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.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

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.

jConfirm with this existing code

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"; } ...

Wrap text after particular symbol with jQuery

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: &...