jQuery,奇怪的焦点行为
这是问题所在。我的页面中有多个标签表单。他们应该是独立的,但行为却很奇怪。如果我在第一个表单中写入或执行任何其他操作,然后在第二个表单的标签上按“X”,它不会注意到我正在处理不同的表单。我尝试更好地解释它:如果我在表单中工作时按 X,
$(this).attr('id')
则返回正确的 id。如果我在处理其他表单时按 X,相同的代码将返回错误的 id。显然它返回我正在处理的表单的 id。
我认为问题与一些奇怪的焦点条件有关(键盘位于一个窗体上,而鼠标指针单击另一个窗体上)。我该怎么解决这个问题?
编辑:表单的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 </span><a href="#" title="Removing tag">x</a></span><span class="tag"><span>efaefea </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>
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 </span><a href="#" title="Removing tag">x</a></span><span class="tag"><span>efaefea </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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
try this: