jQuery 获取锚点值
我正在尝试获取单击的锚点的值,但我不确定正在单击哪个锚点或如何使用 jquery 锁定它。我有一个 document.ready 函数
$(document).ready(function () {
var ActiveBlogStats = $('#BlogSelectList');
$('#BlogSelectList').click(function () {
alert(ActiveBlogStats.text)
}); })
这是它正在处理的 id
<ul class="submenu" id="BlogSelectList">
<xsl:for-each select="oohru/user/oohblog">
<li>
<a>
<xsl:attribute name="href">#<xsl:value-of select="normalize-space(blogid)"/></xsl:attribute>
<xsl:value-of select="oohblogurl"/>
</a>
</li>
</xsl:for-each>
<li><a href="AddNewBlog.aspx">+ Create a new oohblog</a></li>
</ul>
如何获取实际被单击的锚点的 href?我不知道如何制作 document.ready,即使对于文档准备好之前不存在的项目也是如此。 我想我可以从 URL 中获取 # 值,因为当他们点击一个值时,它会更新 URL,但我宁愿直接从点击中获取它。
I am trying to get the value of a clicked anchor but I am not sure which anchor is being clicked or how to latch onto it with jquery. I have a document.ready function
$(document).ready(function () {
var ActiveBlogStats = $('#BlogSelectList');
$('#BlogSelectList').click(function () {
alert(ActiveBlogStats.text)
}); })
Here is the id that it is working on
<ul class="submenu" id="BlogSelectList">
<xsl:for-each select="oohru/user/oohblog">
<li>
<a>
<xsl:attribute name="href">#<xsl:value-of select="normalize-space(blogid)"/></xsl:attribute>
<xsl:value-of select="oohblogurl"/>
</a>
</li>
</xsl:for-each>
<li><a href="AddNewBlog.aspx">+ Create a new oohblog</a></li>
</ul>
How can I get the href of the actual anchor being clicked? I don't see how to make a document.ready even for items that don't exist until after the document is ready.
I suppose I could get the # value from the URL since when they click one it will update the URL but I would rather get it directly from the click.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您的内容是动态生成的,您可能需要查看 .live() (或 delegate())( http: //api.jquery.com/live/ | http://api.jquery.com/delegate /)
您的代码将类似于:
If your content is dynamically generated, you may want to look into .live() (or delegate()) ( http://api.jquery.com/live/ | http://api.jquery.com/delegate/)
Your code would then look something like:
您可以通过以下方式获取 href:
如果您需要阻止它重定向,您可以这样做:
You could get the href with something like this:
And if you needed to stop it from redirecting, you could do: