简体   繁体   中英

jQuery, weird focus behaviour

我的2个标签表格

Here is the problem. I have multiple tag forms in my page. They are supposed to be independent but there's a weird behaviour. If i write in the first form or do any other action and then i press the "X" on a tag of the second form, it doesn't noticed i'm working on a different form. I try to explain it better: if i press X while working in a form,

$(this).attr('id') 

return the correct id. The same code returns a wrong id if i press X while working on the other form. Obviously it returns the id of the form I'm working on.

I think the problem is related to some weird focus condition (the keyboard is on a form while the mouse pointer click in another form). How am i supposed to solve that?

EDIT: form's html

 <form>

<input id="tagbox_infodisc_discussion_65" class="tag_field" object_type="infodisc_discussion" object_id="65" owner="Infodisc" owner_id="1" cancreatetag="1" canaddtag="1" canremovetag="1" value="['hi mom','efaefea']" $type="text" style="display: none; "><div id="tagbox_infodisc_discussion_65_tagsinput" class="tagsinput"><span class="tag"><span>hi mom&nbsp;&nbsp;</span><a href="#" title="Removing tag">x</a></span><span class="tag"><span>efaefea&nbsp;&nbsp;</span><a href="#" title="Removing tag">x</a></span><div id="tagbox_infodisc_discussion_65_addTag"><input id="tagbox_infodisc_discussion_65_tag" value="" data-default="" style="color: rgb(0, 0, 0); " class="ui-autocomplete-input" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true"></div><div class="tags_clear"></div></div>

</form>

try this:

$('input').live('click', function(){
  console.log($(this).prop('id'));
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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