jquery val() contains()

后端 未结 5 1561
青春惊慌失措
青春惊慌失措 2021-02-18 17:40

I want to know if the textarea value contains a certain word. This is not working for me.

var value = $(\'#embedModal textarea\').val();
if($(value).contains(\'i         


        
相关标签:
5条回答
  • 2021-02-18 18:09

    You can do this as well:

    if($('#embedModal textarea:contains("iframe")').length > 0){
        //TODO: do stuff
    }
    
    0 讨论(0)
  • 2021-02-18 18:11

    Try doing it like this:

    $('#embedModal textarea:contains("iframe")').each(function() {
      //Do something
    });
    

    edit

    Example

    0 讨论(0)
  • 2021-02-18 18:11

    Try following code.....

    code:

                 <textarea rows="4" cols="9">Something iframe</textarea>
                 <textarea rows="4" cols="9">Something</textarea>
    
                   var obj=$("textarea:contains('iframe')");
    
                       if(obj){
    
                                obj.css("background-color", "red");
    
                             }
    
    0 讨论(0)
  • 2021-02-18 18:16

    Try javascript

    if (value.indexOf('iframe') >= 0) {
    

    JQuery contains is for DOM elements, not strings.

    0 讨论(0)
  • 2021-02-18 18:23

    this works:

    $.contains( document.documentElement, document.body ); // true
    
    var babyEl = $('div#id');
    var daddyEl = $('div#ID');
    
    if($.contains(babyEl, daddyEl)) {
        //do fun stuff
    }
    
    0 讨论(0)
提交回复
热议问题