2016-09-16 81 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>