简体   繁体   English

jQuery如果div包含文本,切换按钮

[英]jQuery if div contains text, toggle button

I'm trying to get a button to be toggled if a div contains a string of text. 如果div包含一串文本,我试图让一个按钮切换。 Something like: 就像是:

$(document).ready(function(){
$(function() {
if ('$div#trackingnumber:contains('Hello')');') {
    $("dinput#submitam").toggle()});
}
});

Does anybody know how to do this? 有人知道怎么做这个吗?

You are on the right way. 你是正确的方式。 I only see some syntax errors. 我只看到一些语法错误。 Try this 尝试这个

$(document).ready(function(){
     if ($("#trackingnumber:contains('Hello')").length != 0) 
     {
         $("dinput#submitam").toggle();
     }
});

Checkout this jsFiddle too. 结帐这个jsFiddle也是。

Just do like this 就这样做

$(document).ready(function(){
  if ($("div#trackingnumber:contains('Hello')").length > 0)
  $("dinput#submitam").toggle();
});
$(document).ready(function() {
    if ( $("#trackingnumber:contains('Hello')").length > 0 ) {
        $("#submitam").toggle();
    }
});

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

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