Opera - Prevent input from having focus

只谈情不闲聊 提交于 2019-12-11 10:19:42

问题


I have a hidden input on one of my pages, and by hidden, I mean visible, but just looks like plain text.

Take for example http://jsfiddle.net/imoda/nVhp8/

But I don't want a user to be able to click in it and edit the information. Essentially disabling it, but without setting it to disabled in the html. I think I'm close but whatever I've tried isn't working.

Seems to work in everything except Opera. Help please?


回答1:


Instead of using jQuery, why not simply use the readonly attribute, removing that attribute once the edit button has been clicked?

JS Fiddle.

References:

  • readonly.



回答2:


Use a timeout..

$("input").focus(function(){
    var _this = this;
    setTimeout(function(){_this.blur();},1);
});

and a more extended example at http://jsfiddle.net/gaby/nVhp8/2/



来源:https://stackoverflow.com/questions/6700297/opera-prevent-input-from-having-focus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!