简体   繁体   English

jQuery优先级与Ajax交互

[英]jquery priority interacting with Ajax

I have dynamically created input elements, I would like to do something with JQuery when I click on it. 我已经动态创建了输入元素,当我单击它时,我想对JQuery做一些事情。 At the moment I have an Ajax connection triggered when I click on input element to retrieve some content from the server. 现在,当我单击输入元素以从服务器检索一些内容时,我触发了Ajax连接。 the point is that .click() works only on the second click on the element whereas I would like to fire JQuery and not only Ajax at first click too. 关键是.click()仅在元素的第二次单击上有效,而我想在第一次单击时触发JQuery,不仅是Ajax。

inside my PHP code I have the input elements created and showNews Ajax function called: 在我的PHP代码中,我创建了输入元素,并将showNews Ajax函数称为:

<input id="ac-<?php echo $row['id']; ?>" name="accordion-1" type="radio">
<label  for="ac-<?php echo $row['id']; ?>" onClick="showNews(<?php echo $row['id']; ?>)"><?php echo $row['title']; ?></label>

And with JQuery I would like able to do something like: 借助JQuery,我希望能够执行以下操作:

$(document).ready(function(){
  $("input").click(function(){
    // Doing something here
  });
});

Now it's working at second mouse click. 现在,第二次单击鼠标即可工作。 Could you have a look here. 你能在这里看看吗

click() func works only at second click. click()函数仅在第二次单击时有效。 I need two handled actions on the same element and on the same time. 我需要在同一元素上同时执行两个已处理的操作。

More exact answer could be 更确切的答案可能是

$('input').focus(function(){
   // doing your thing here
})

使用$('input')。focus()代替: http : //api.jquery.com/focus/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM