English 中文(简体)
jquery Point
原标题:jquery click question
  • 时间:2010-09-09 03:53:06
  •  标签:
  • jquery

My html:

<div id="menu"><ul><li>menu one<ul>
<li><a id="home">home</a></li>
<li><a id="contact">contact us</a></li>
</ul></li></ul></div>

Jquery :

    $( #menu ).click(function(){
        alert($(this).find( a ).attr( id ));
    });

我想找到被点击的价值。 我的法典空洞。

最佳回答
$( #menu a ).click(function(){
    alert($(this).html());
});

如果你想要id,那就这样做了。

$( #menu a ).click(function(){
    alert($(this).attr( id ));
});
问题回答

你的定论(a)将归还多个要素。 如果你想用.(each())展示其价值。 Else就是这样做的:find(a)[0]attr(id)

守则:

iii

你的法典为我工作,它每次都把“家庭”归还给第一个后代人<代码>a<>div。 也许,你们会重新审视像现在这样的东西。

  $( #menu a ).click(function(){
        alert($(this).attr( id ));
  });​

http://jsfiddle.net/rsbPt/“rel=”

之所以取得这一成绩,是因为$ (this).find(a)回归一个阵列,因此,为了获得#menu的所有座标,您需要重新编号。 可通过<代码>.each()的功能:

$( #menu ).click(function(){
  $(this).find( a ).each(function(){ alert(this.id) });
});

将向您提供两份<代码>alert(>>>,供您提供,每种文本都有不同的<代码>id。 然后,你可以将<代码>alert(>>)替换成您在每一条 anchor上需要履行的任何职能。





相关问题
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: &...

热门标签