【问题标题】:How to remove 'X' from input type="text/search" control如何从输入类型=“文本/搜索”控件中删除“X”
【发布时间】:2016-09-16 07:19:18
【问题描述】:

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

如:

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+ 浏览器中的输入字段。

任何帮助将不胜感激。

【问题讨论】:

    标签: javascript jquery html css internet-explorer


    【解决方案1】:

    (未测试,但应该可以)

    $('#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>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-20
      • 2021-12-23
      • 1970-01-01
      • 2015-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多