从输入表单中删除HTML TAG输入
问题描述:
好吧,基本上当我输入时,它不会允许它。
我想添加更多像< > / \ etc我该怎么做?
Ok basically when I type , it won't allow it. I want to add more like < > / \ etc how do I do it?
$("#in1").keypress(function (evt) {
if (String.fromCharCode(evt.which) == ",")
return false;
});
<input type="text" id="in1">
可在此处查看演示。 http://jsfiddle.net/QshDd/38/
Can see the demo here. http://jsfiddle.net/QshDd/38/
答
如果你有一个不允许的字符列表,你可以这种方式禁止它们:
If you have a list of disallowed characters, you can forbid them in this fashion:
$("#in1").keypress(function (evt) {
return [',', '<', '>', ].indexOf(String.fromCharCode(evt.which)) === -1;
});