Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用jquery查找内部包含指定文本的按钮?_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 如何使用jquery查找内部包含指定文本的按钮?

Javascript 如何使用jquery查找内部包含指定文本的按钮?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我有这个代码结构,我想搜索包含文本“离线退款”的span 然后将类hide_按钮添加到父标记“button”中 基本上我想隐藏有“离线退款”文本的按钮 离线退款 使用jQuery 提前感谢试试这个 $('button span').each ( function() { if($(this).text() === "Refund Offline" ) { $(this).parent().addClass ( 'hide_button' ); } })

我有这个代码结构,我想搜索包含文本“离线退款”的span 然后将类hide_按钮添加到父标记“button”中

基本上我想隐藏有“离线退款”文本的按钮


离线退款
使用jQuery

提前感谢

试试这个

$('button span').each ( function() {
    if($(this).text() === "Refund Offline" )
    {
        $(this).parent().addClass ( 'hide_button' );
    }
});
$('button span:contains("Refund Offline")').parent().addClass("hide_button");

如果您的文本不在按钮的子级范围内(或者您不能100%确定它是否在),请使用


最近的
将返回最近的
按钮
元素

这是否与字符串“离线退款”完全匹配?不,不是。它匹配所有跨度,其中:是按钮的子级并包含字符串“Return Offline”。您可以使用
$(“按钮:has(>span:contains('Return Offline'))保存函数调用。addClass('hide_button')“按钮:包含”
。。。其主要思想是,如果您不确定button>span中是否有文本,可以通过这种方式搜索更多节点。当然,您应该尝试编写更具体的选择器。如果可以的话。
$("button > span:contains('Refund Offline')").parent().addClass("hide_button");
$('button span:contains("Refund Offline")').parent().addClass("hide_button");
$(":contains('Refund Offline')").closest('button').addClass("hide_button");