【问题标题】:To use Jquery Contains keyword for textbox使用 Jquery Contains 关键字作为文本框
【发布时间】:2013-05-02 04:07:51
【问题描述】:

如何将 jquery contains 用于文本框,我已附上小提琴链接供您参考,

<div id="txtCon">
  <input type="text" name="man-news" />

  <input type="text" name="milkman" />
  <input type="text" name="letterman2" />
  <input type="text" name="newmilk" />
    has
</div>


Script:


$('input[name*="new"]').val('has');

$('input:text:contains("has")').css("color","red");

链接:

http://jsfiddle.net/vigneshjayaraman/Ytsr5/2/

【问题讨论】:

标签: javascript jquery html


【解决方案1】:

:contains 只查看元素的内容input 元素没有内容。您必须改用.filter() [docs]

$('input[name*="new"]').filter(function() {
    return this.value.indexOf('has') > -1;
}).css(...);

【讨论】:

    猜你喜欢
    • 2017-09-09
    • 1970-01-01
    • 2019-10-03
    • 1970-01-01
    • 2015-11-16
    • 1970-01-01
    • 2012-04-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多