我有一个包含两个选择字段的表单,对于这两个字段,我使用select2来匹配和标记化插入到字段中的内容。我需要将由新行分隔的输入列表转换为由空格分隔的列表(因为IE不会自动执行此操作)。
我有以下代码,可以很好地处理任何<input>字段:
$('#editor').bind('paste', function (e) {
var clipped = window.clipboardData.getData('Text');
clipped = clipped.replace(/(\r\n|\n|\r)/gm, " "); //replace newlines with spaces
$(this).val(clipped);
alert(clipped);
return false; //cancel the pasting event
});但是如果#editor是一个<select>字段,它似乎就不起作用了。
<form method="POST" action="/run" class="ui-widget" onsubmit=" return confirmSubmit(this, 'run',true) ">
Editor:
<select name="editor" id="editor" multiple style="width: 200px">
<option>ALL</option>
</select>
<input type="submit" value="Submit">
</form>你知道少了什么吗?
发布于 2015-07-13 21:20:39
我不相信在select上粘贴是可能的
一种解决方法可能是:
绑定keydown事件
编辑:
https://stackoverflow.com/questions/30865722
复制相似问题