如何删除' X'来自输入类型=" text / search"控制

时间:2016-09-16 07:19:18

标签: javascript jquery html css internet-explorer

我同意这个问题有很多答案。

如:

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,并且已经通过兼容模式进行了检查,一切都很好,我没有在任何浏览器中测试这个(因为我不必)我只想删除 X 来自IE 10+浏览器的输入字段。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

(未经测试但应该有效)

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

现在测试:

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