事件 – 如何使用角度模拟Tab键按键
我有兴趣做一个非常简单的自动标签功能.我想以编程方式为访问者按“标签”.我似乎无法弄清楚如何在标准JS中实现这一点(即 – 不使用jQuery的.trigger()).
用法:< input auto-tab =“3”> directive('autoTab',[function () { return { restrict: "A",scope: false,link: function (scope,el,attrs) { el.bind('keyup',function () { if (el.val().length >= attrs.autoTab) { //document.dispatchEvent(); } }); } } }]) 解决方法
我不认为这是可能的.查看
this post和
this SO question:
您可以尝试不同的方法:更改您的指令,以便它接收下一个应该关注的元素的id: app.directive('autoTabTo',[function () { return { restrict: "A",attrs) { el.bind('keyup',function(e) { if (this.value.length === this.maxLength) { var element = document.getElementById(attrs.autoTabTo); if (element) element.focus(); } }); } } }]); 然后你可以像这样使用它: <input type="text" id="input1" auto-tab-to="input2" maxlength="5"/> <input type="text" id="input2" auto-tab-to="input1" maxlength="3"/> 工作演示here. 这不完全是你想要的,但我担心通过模拟TAB键击不可能做到这一点. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |