[英]JQuery Click on a div which contains a specific text
I am trying to click on a div while contains a specific text. 我尝试在包含特定文本的同时单击div。
This is where I am: 这是我的位置:
$( document ).ready(function() {
$('.myclass li.active .short-text'["value=thetext"]).click();
});
The code above is not doing it ... How can I get this to work? 上面的代码没有执行此操作。如何使它正常工作?
You can use contains-selector 您可以使用包含选择器
Select all elements that contain the specified text.
选择所有包含指定文本的元素。
$('.myclass li.active .short-text:contains("someText")').click();
this is the jquery method of checking if something contains a text. 这是检查某些内容是否包含文本的jquery方法。 i don't know if you can use it as a click function though
我不知道你是否可以将其用作单击功能
$('.myclass li.active .short-text:contains("thetext")').click();
Something like this should do the trick. 这样的事情应该可以解决问题。 Not sure if there is a better solution.
不知道是否有更好的解决方案。
$(document).ready(function() {
$("div").click(function() {
if($(this).text() == "The text") {
//Code here
});
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.