代码之家  ›  专栏  ›  技术社区  ›  MGames

Jquery-如何在这里使用contains?

  •  0
  • MGames  · 技术社区  · 7 年前

    如何使用contains搜索占位符来搜索单词“name”并设置值,而不是搜索占位符的确切值。

    以下是html:

          <input autocorrect="off" placeholder="full name here" id="order_billing_name" name="order[billing_name]" size="30" class="" type="text">
    

    我如何使用contains搜索“name”并设置值,而不是搜索确切的值“full name here”

     $('[placeholder="full name here"]').val('name here');
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   guest271314    7 年前

    可以使用属性值包含选择器

    $("[placeholder*=name]").val("name here")
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
    </script>
    <input autocorrect="off" 
           placeholder="full name here" 
           id="order_billing_name" 
           name="order[billing_name]" 
           size="30" 
           class="" 
           type="text">