为提升您的使用体验,本站正在维护,部分功能暂时无法使用。如果本站文章无法解决您的问题,您想要向社区提问的话,请到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 提问,我们的支持社区将会很快回复您的疑问。

搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

Click event incorrectly associated after DOM manipulation

  • 1 个回答
  • 1 人有此问题
  • 1 次查看
  • 最后回复者为 the-edmeister

more options

I have a page with input elements and a span element styled as a button. I register change event handlers on the input elements, to do validation when the input values are changed. If the inputs are invalid, I add content to a div on the page to indicate the problem. I also register a click event handler on the span styled as a button.

When I edit an input then immediately click on the span (i.e. without focus leaving the input element before clicking on the span) I see:

1) mousedown on span 2) change on input 3) mouseup on input

This occurs only when I modify the DOM in the change event handler on the input. If I don't modify the DOM then I see:

1) mousedown on span 2) change on input 3) mouseup on span 4) click on span

In the first case, I see the mouseup associated with the input element rather than the span element, even though it has the same coordinates as the mousedown which is associated with the span element. Given the coordinates are within the bounds of the span element and outside the bounds of the input element, I don't understand why the mouseup is associated with the input element rather than the span element.

There is an example of this at http://jsfiddle.net/4zx8rm7c/.

I see this behaviour in Firefox 34.0.5 and Chrome 39.0.2171.95 m.

If the association of the mouseup event with the input element, despite the seemingly unrelated coordinates of the mouse event, is intended behaviour, I need to understand why this is. I have looked at COM Level-2 event specifications (briefly) and I don't see an obvious explanation.

I have a page with input elements and a span element styled as a button. I register change event handlers on the input elements, to do validation when the input values are changed. If the inputs are invalid, I add content to a div on the page to indicate the problem. I also register a click event handler on the span styled as a button. When I edit an input then immediately click on the span (i.e. without focus leaving the input element before clicking on the span) I see: 1) mousedown on span 2) change on input 3) mouseup on input This occurs only when I modify the DOM in the change event handler on the input. If I don't modify the DOM then I see: 1) mousedown on span 2) change on input 3) mouseup on span 4) click on span In the first case, I see the mouseup associated with the input element rather than the span element, even though it has the same coordinates as the mousedown which is associated with the span element. Given the coordinates are within the bounds of the span element and outside the bounds of the input element, I don't understand why the mouseup is associated with the input element rather than the span element. There is an example of this at http://jsfiddle.net/4zx8rm7c/. I see this behaviour in Firefox 34.0.5 and Chrome 39.0.2171.95 m. If the association of the mouseup event with the input element, despite the seemingly unrelated coordinates of the mouse event, is intended behaviour, I need to understand why this is. I have looked at COM Level-2 event specifications (briefly) and I don't see an obvious explanation.

被采纳的解决方案

This forum is intended for user support, not for web development issues. Try posting at the Web Development / Standards Evangelism forum at MozillaZine. The contributors over there are more knowledgeable about web page development issues with Firefox. http://forums.mozillazine.org/viewforum.php?f=25 You'll need to register and login to be able to post in that forum.

定位到答案原位置 👍 0

所有回复 (1)

more options

选择的解决方案

This forum is intended for user support, not for web development issues. Try posting at the Web Development / Standards Evangelism forum at MozillaZine. The contributors over there are more knowledgeable about web page development issues with Firefox. http://forums.mozillazine.org/viewforum.php?f=25 You'll need to register and login to be able to post in that forum.