我正在寻找一种方法来清理我粘贴到浏览器中的输入,这可能与jQuery有关吗?
到目前为止,我已经设法做到了这一点:
$(this).live(pasteEventName, function(e) {
// this is where i would like to sanitize my input
return false;
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,由于这个"次要"问题,我的发展已经开始戛然而止.如果有人能指出我正确的方向,我真的会让我成为一个快乐的露营者.
我有一个jquery令牌tagit插件,我想绑定到粘贴事件以正确添加项目.
我能够像这样绑定到粘贴事件:
.bind("paste", paste_input)
Run Code Online (Sandbox Code Playgroud)
...
function paste_input(e) {
console.log(e)
return false;
}
Run Code Online (Sandbox Code Playgroud)
如何获取实际粘贴的内容值?
我试过了(jsfiddle),但它没有用.
你怎么能看到警报是空的.就像.val()函数在复制字符串之前启动.
$(document).on('paste', '#pasteIt', function(){
alert($("#pasteIt").val());
var withoutSpaces = $("#pasteIt").val();
withoutSpaces = withoutSpaces.replace(/\s+/g, '');
$("#pasteIt").text(withoutSpaces);
});
Run Code Online (Sandbox Code Playgroud)
为什么?
我有一个包含以下模板的组件:
<div>
{{textarea value=content autofocus="autofocus"}}
<button {{action 'cancel'}}>cancel</button>
</div>
Run Code Online (Sandbox Code Playgroud)
我怎样才能paste在我的组件中听这个textarea上的事件?
我试着听一下粘贴动作,但这似乎不起作用:
App.EditableTextComponent = Ember.Component.extend({
templateName: 'components/editable-text',
actions: {
paste: function() {
console.log(arguments);
}
}
});
Run Code Online (Sandbox Code Playgroud)