简体   繁体   English

在HREF链接中使用JQuery

[英]Using JQuery within an HREF link

I'm trying to use the following action which works fine in console but i'd like to have it fire when a link is clicked. 我正在尝试使用以下操作,该操作在控制台中可以正常工作,但是我希望在单击链接时将其触发。

Code: 码:

$('#angrid656 > div.angrid > div:nth-child(2) > div > table > tbody > tr:nth-child(1) > td.angrid-item-buttons.ng-scope > a.btn.btn-info.btn-accent.opacity75').click()

I've created the link like this but it's not working properly: 我已经创建了这样的链接,但无法正常工作:

<a href="$('#angrid656 > div.angrid > div:nth-child(2) > div > table > tbody > tr:nth-child(1) > td.angrid-item-buttons.ng-scope > a.btn.btn-info.btn-accent.opacity75').click()"><div class="title">[Title]</div></a>

If you want to execute Javascript in an href attribute, you have to begin with javascript: 如果要在href属性中执行Javascript,则必须以javascript:开始javascript:

<a href="javascript:$('#angrid656 > div.angrid > div:nth-child(2) > div > table > tbody > tr:nth-child(1) > td.angrid-item-buttons.ng-scope > a.btn.btn-info.btn-accent.opacity75').click()">...</a>

It doesn't matter whether it's plain Javascript or jQuery (which is just a library of Javascript functions). 不管是普通的Javascript还是jQuery(这只是Javascript函数库)。

You can also use an onclick attribute, and use href="#" to prevent the link from going anywhere automatically. 您还可以使用onclick属性,并使用href="#"防止链接自动转到任何地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM