[英]Can jquery traverse the entire DOM and find the word Update in a href
Seems that people are clicking on Enter key on board and while I can disable that I have business analysts wanting me to have the Enter key "click" the Update link 似乎人们在板上单击Enter键,而我可以禁用时,我有业务分析师希望我让Enter键“单击” Update链接
Since this is asp.net gridview I don't have a lot of control of it plus there are many rows in which the __doPostBack data is different 由于这是asp.net gridview,因此我对其没有太多控制,另外还有很多行的__doPostBack数据不同
How can I detect the word "Update" ( it was "Edit" along with many other rows having that Edit link as well) 如何检测单词“ Update”(它是“ Edit”以及其他许多具有该Edit链接的行)
<a href="javascript:__doPostBack('GridView1$_ctl2$_ctl0','')">Update</a>
Update: 更新:
I want to find a keyword in an href that is in a table. 我想在表格的href中找到关键字。
So "Update" is the keyword that is in href which is in a 因此,“更新”是href中的关键字,该关键字位于
<table>
<tr>
<td>
<a href..>Update</a>
</td>
</tr>
</table>
Update 2: 更新2:
Here is a Fiddle http://jsfiddle.net/bthorn/vzjLzfck/ 这是小提琴http://jsfiddle.net/bthorn/vzjLzfck/
I believe that this does FIND if update is there 我相信如果有更新,这确实可以找到
var y = $('a').filter(function(index) { return $(this).text() === "Update"; });
I changed Update to "Updated" and length went from 1 to 0 ....
So then if that is working, I want to then proceed to have that Link executed or whatever do that essentially It is like someone is clicking on that href link 因此,如果这是可行的,那么我想继续执行该Link或实质上执行的所有操作,就像有人单击该href链接一样
Final working code 最终工作代码
$(document).keypress(function (e) {
if (e.which == 13) {
$("a").each(function () {
$("a").filter(function () {
var s = $(this).text() === "Update";
if (s == true) {
//console.log('yes in');
this.click();
}
});
return false;
});
return false;
}
});
If you want to target any href
that contains the word "Update" you can use jQuery's filter function on the href
如果您要定位包含“更新”一词的
href
,您可以在href
上使用jQuery的过滤器功能
$("a").filter(function(){
return $(this).attr('href').indexOf("Update");
});
If you want the text to contain "Update" you can use: 如果希望文本包含“更新”,则可以使用:
$("a").filter(function(){
return $(this).text() === "Update";
});
$("body").on("keypress", function(e) {
if(e.which != 13) {
return;
};
$("a").each(function() {
var link = $(this);
if(link.text() == "Update") {
console.log("woot");
window.open(link.attr("href"));
};
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.