从鼠标左键的自动填充中取消选中值 [英] Value not getting selected from an Autocomplete on Mouse button click

查看:202
本文介绍了从鼠标左键的自动填充中取消选中值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Jquery自动填充。它的工作很好当我从键盘箭头键上下移动或将鼠标悬停在特定值上时,将选择值。但是当我按下按钮将所选值放在文本框内不起作用的时候,如果我按键盘上的Enter键,则文本框中输入值。



让我给我我的代码进行自动完成::



$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b $(input#assignedtoid)。autocomplete({
source:myVar2
});
});

< input dojoType =dijit.form.ValidationTextBoxid =assignedtoidname =assignedtonamerequired =trueonfocus =hello()value =<%= session。的getAttribute( 用户名)%>的onblur = valassignedtoid() >

上面的代码 myVar2 是我的数据 Json 为自动完成分配了一个来源的表单。价值在自动完成中正常。 onFocus 事件在输入标签我调用 hello()函数。为什么没有在鼠标按钮点击获得该值。但是从那里我拿起代码的网站。在鼠标单击以及进入按下时,值将被选中。 网站是::

  http://jqueryui.com/演示/自动完成/ 

这里唯一的区别是源是静态的我从数据库中获取 Json 直到 myVar2 的形式。我正在使用IE。使用 dijit.form.ValidationTextBox 作为我的输入



请帮忙。谢谢..



编辑部分::



我已导入以下js文件::

 < script type =text / javascriptsrc =https://ajax.googleapis.com/ajax/libs/jquery/ 1.7.2 / jquery.min.js>< /脚本> 
< script type =text / javascriptsrc =https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js>< / script>
< script type =text / javascriptsrc =http://dev.jquery.com/view/trunk/plugins/autocomplete/jquery.autocomplete.js>< / script>
< link href =http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css =stylesheettype =text / css />
< script src =http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js>< / script>

当我在 Google Chrome 我没有任何自动完成。我确实得到一个错误那个::

 < script type = text / javascriptsrc =http://dev.jquery.com/view/trunk/plugins/autocomplete/jquery.autocomplete.js>< / script> 

未找到。其实它的无效了。但是当我在IE上运行时,我的自动完成功能会很好。这可能是原因吗?也可以告诉我哪个Jquery从上面导入我应该删除,如果其中任何一个是额外的。金达迷惑了



我已经从这里获取了代码::

  http: //jqueryui.com/demos/autocomplete/ 

再次感谢。

解决方案

从您的标记中删除 onfocus =hello()并修复javascript:

  dojo.require(dijit.form.ValidationTextBox); 

dojo.ready(function(){
var myVar2 =<%= request.getAttribute(variable1)%> ;;
$(input#assignedtoid ).autocomplete({
source:myVar2
});
});

BTW,你为什么不想使用 dijit.form.ComboBox 为纯dojo解决方案?



更新



如果你想使用google cdn,你需要这些导入:

 < link rel =stylesheethref =http: //ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/themes/base/jquery-ui.csstype =text / cssmedia =all/> 
< script src =http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.jstype =text / javascript>< / script>
< script src =http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/jquery-ui.min.jstype =text / javascript>< /脚本>


I have a Jquery Autocomplete. Its working fine. Values are selected when i move up and down from keyboard arrow key or hover a mouse on a particular value. But when i press button to put my selected value inside text box it doesn't work, instead if i press enter on keyboard the value is inputted in text box.

Let me give me my code for auto complete ::

$(document).ready(function hello(){
var myVar2 = <%=request.getAttribute("variable1")%>
      $("input#assignedtoid").autocomplete({
  source: myVar2
 });
});

<input dojoType="dijit.form.ValidationTextBox" id="assignedtoid" name="assignedtoname"  required="true" onfocus="hello()" value=<%=session.getAttribute("Username")%> onblur="valassignedtoid()">

In above code myVar2 is my data in Json form that is assigned a source for autocomplete. Values coming fine in autocomplete. OnFocus event in input tag i call hello() function. Why it is that value is not getting selected on mouse button click. However the site from where i picked up the code. the value is getting selected on Mouse click as well as on enter pressing. The site is ::

http://jqueryui.com/demos/autocomplete/

Here the only diff is that there Source is static i am getting it from database in the form of Json thru myVar2. I am using IE. Using dijit.form.ValidationTextBox as my input

Please help. Thanks ..

The Edited Part ::

i have Imported The following js files::

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/autocomplete/jquery.autocomplete.js"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

And when i run it in Google chrome i don't get any auto complete. I do get an error that ::

<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/autocomplete/jquery.autocomplete.js"></script>

is not found. And indeed its not valid anymore. But my auto complete works great when i run it on IE. Can this be the reason ? Also can u tell me which Jquery imports from the above i should delete if any of them is extra. Kinda confused.

i have taken the code from here ::

http://jqueryui.com/demos/autocomplete/

Thanks again.

解决方案

Remove onfocus="hello()" from your markup, and fix javascript:

dojo.require("dijit.form.ValidationTextBox");

dojo.ready(function () {
  var myVar2 = <%=request.getAttribute("variable1")%>;
  $("input#assignedtoid").autocomplete({
    source: myVar2
  });
});

BTW, Why don't you want to use dijit.form.ComboBox for pure dojo solution?

UPDATE

If you want to use google cdn, you need these imports:

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/themes/base/jquery-ui.css" type="text/css" media="all" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/jquery-ui.min.js" type="text/javascript"></script>

这篇关于从鼠标左键的自动填充中取消选中值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆