2016-09-16 44 views
0

我同意這個問題有很多答案。如何從輸入type =「text/search」控件中刪除'X'

如:

ans 1

ans 2

ans 3

等等,但已經嘗試了所有這些,但我還是無法從刪除 「X」輸入字段。

我剛剛創建簡單的輸入控制:

<input type="text" id="RemoveX" /> 

這裏是我的CSS:

input[type=text]::-ms-clear { display: none; width : 0; height: 0; } 
input[type=text]::-ms-reveal { display: none; width : 0; height: 0; } 
input[type="search"]::-webkit-search-decoration, 
input[type="search"]::-webkit-search-cancel-button, 
input[type="search"]::-webkit-search-results-button, 
input[type="search"]::-webkit-search-results-decoration { display: none; } 

#RemoveX::-ms-clear { display: none; width : 0; height: 0; } 
#RemoveX::-ms-reveal { display: none; width : 0; height: 0; } 
#RemoveX::-webkit-search-decoration, 
#RemoveX::-webkit-search-cancel-button, 
#RemoveX::-webkit-search-results-button, 
#RemoveX::-webkit-search-results-decoration { display: none; } 

我使用IE 11,並用兼容模式一切檢查被罰款,我沒有測試此在任何瀏覽器中(因爲我不需要),我只想從IE 10+瀏覽器的輸入字段中刪除X

任何幫助將不勝感激。

回答

0

(未經測試,但它應該工作)

$('#yourInput').bind('input', function() { 
    var current = $('#yourInput').val(); 
    var newData = current.replace("X",""); 
    $('#yourInput').val(newData); 
}); 

經過測試:

<!doctype html> 
 
<html> 
 
\t <head> 
 
\t \t <meta charset="utf-8"> 
 
\t \t <script src="https://code.jquery.com/jquery-3.1.0.min.js"></script> 
 
\t \t <title>asd</title> 
 
\t </head> 
 
\t <script type="text/javascript"> 
 
\t $(document).ready(function(){ 
 
\t \t $('#myInput').bind('input',function() { 
 
\t \t \t var current = $('#myInput').val(); 
 
\t \t \t var newData = current.replace("X",""); 
 
\t \t \t newData = newData.replace("x",""); // small x if you want 
 
\t \t \t $('#myInput').val(newData); 
 
\t \t }); 
 
\t }); 
 
\t </script> 
 
\t <body> 
 
\t \t <input type="text" id="myInput" /> 
 
\t </body> 
 
</html>

相關問題