2013-05-02 112 views
-2

如何使用jQuery的關鍵字包含文本框,我重視的小提琴鏈接,你的代碼參考,使用jQuery包含用於文本框

<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/

+0

我想你理解錯了包含選擇,請看看這個: http://www.w3schools.com/jquery/jquery_ref_selectors.asp – 2013-05-02 04:13:27

+0

可能複製[這裏](http://stackoverflow.com/questions/4939071/jquery-val-contains)
看看那裏! – MISJHA 2013-05-02 04:14:13

回答

1

:contains不僅外觀在元素的內容處。 input元素沒有內容。你必須使用.filter()[docs]代替:

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