大佬教程收集整理的这篇文章主要介绍了jquery-ui – 在Internet Explorer中意外调用JQuery UI自动完成焦点(),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在IE中,当您键入并且菜单显示项目列表时,从菜单项中选择项目时,再次调用focus().这个对focus()的额外调用只发生在IE中.副作用是从文本字段中清除所选菜单项.
通过使用autocomplete.focus()事件,我有一个非常原始的解决方案.当用户将鼠标悬停在选定的菜单项上时会触发此事件.在这里,我可以设置一个全局布尔变量,可以用来告诉输入字段上的focus()事件,菜单项是活动的/可见的,因此不清除输入值.当然,这是一个黑客!
这个问题有替代方案(不那么hacky!)吗?
这是代码:
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Autocomplete demo</title> <link type="text/css" href="css/ui-lightness/jquery-ui-1.8.18.custom.css" rel="stylesheet" /> <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script> <script type="text/javascript" src="js/jquery-ui-1.8.18.custom.min.js"></script> </head> <body> <script> $(function () { var availableTags = [ "ActionScript","AppleScript","Asp","BASIC","C","C++","Clojure","COBOL","ColdFusion","Erlang","Fortran","Groovy","Haskell","Java","JavaScript","Lisp","Perl","PHP","Python","Ruby","Scala","scheR_811_11845@e" ]; $("#tags").autocomplete({ source: availableTags,focus: function (event,ui) { // This event fires when an item from the menu is SELEcted (in focus) // set some variable here to tell the focus() call to the text field not to clear the value from the input field },}); $("#tags").focus(function () { // clear the input value $("#tags").val(""); }); }); </script> <div class="demo"> <div class="ui-widget"> <label for="tags">Tags: </label> <input id="tags" value="Enter your keywords..." /> </div> </div> </body> </html>
通过对此解决方案的轻微调整,并在所提供的答案的帮助下,现在可以在IE 8& 9.
$(document).ready(function () { var availableTags = [ "ActionScript","scheR_811_11845@e" ]; $("#tags").autocomplete({ source: availableTags }); $("#tags").focus(function () { // clear the input value $("#tags").val(""); return false; }); })
$("#tags").focus(function () { // clear the input value $("#tags").val(""); return false; });
此外,在焦点声明后,您看起来有一个额外的(尾随)逗号.可能想要清理它.
在jsbin.com中稍微使用了你的代码之后,我想我找到了解决你的IE特定问题的解决方案,但我不是百分之百为什么它只会在IE中死掉.
示例:http://jsbin.com/aqituk/2/edit#javascript,html
区别在于将$(function(){…更改为完整的文档就绪函数,$(document).ready(function(){…
希望这可以帮助!
以上是大佬教程为你收集整理的jquery-ui – 在Internet Explorer中意外调用JQuery UI自动完成焦点()全部内容,希望文章能够帮你解决jquery-ui – 在Internet Explorer中意外调用JQuery UI自动完成焦点()所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。