简体   繁体   English

为什么在Safari中单击/关注子文本框时会自动触发父元素单击事件?

[英]Why parent element click event fires automatically when child textbox is clicked/focus in Safari?

I have following HTML structure 我有以下HTML结构

[Checkbox] [Text] [Input element (Show if check-box is checked)]

<span class='spGrpContainer'>
  <label id='stepGH_Group1' class='lblStep GHSteps lblGroupheader' stepid='1' stepname='Group1' childcontainer='ulGH_grp1Steps'>
    <label><input type='checkbox' onchange="Javascript:HideUnHideSubItems();" /><span class='sptext spGHStepName'>Check Me</span></label>
    <label class='lblRanking' style='display: none;'><input id='rnkbox_Scr' class='txtImportance' type='number' min='0' max='100' step='1' value='' /></label>
  </label>
</span>

When input element click, the checkbox is automatic hide in Safari browser . 单击输入元素后,该复选框将自动隐藏在Safari browser In all other major browser like Chrome, IE, Firefox it's working nice. 在所有其他主流浏览器(如Chrome,IE,Firefox)中,它运行良好。 Check Fiddle 检查小提琴

I also tried event.stopPropagation() for resolving event bubbling, but its didn't helpful. 我也尝试使用event.stopPropagation()来解决事件冒泡,但是它没有帮助。 Check Fiddle 检查小提琴

Is there any way to resolve this issue? 有什么办法解决这个问题?

Click is an event that bubbles up. 点击是冒泡的事件。 You might want to take a look at the JavaScript Documentation by MDN about event bubbling. 您可能想看一下MDN的JavaScript文档中有关事件冒泡的信息。 http://javascript.info/tutorial/bubbling-and-capturing http://javascript.info/tutorial/bubbling-and-capturing

event.stopPropagation() should prevent it from happening. event.stopPropagation()应该防止它发生。 Stop propagation documentation 停止传播文档

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

相关问题 单击父项时调用子项单击事件 - Calling Child click event when parent is clicked 当孩子被点击时触发父点击事件 - trigger parent click event when child is clicked 单击元素的子元素时忽略单击事件 - Ignoring click event when child of element is clicked 在ios的Safari浏览器中,当有一个“ onclick”内联孩子时,有一个“ onmouseover”内联父母时,为什么单击该孩子时触发了mouseover事件? - In safari of ios, when there is a “onclick” inline a child, and a “onmouseover” inline a parent, why mouseover event fired when click the child? 单击子元素时如何防止父div失去焦点 - How to prevent parent div lose focus when child element is clicked jQuery单击父项上的事件,但查找子项(单击)元素 - jQuery click event on parent, but finding the child (clicked) element 防止在单击子下拉菜单时触发父元素单击事件 - Prevent parent element click-event to trigger when child-dropdown clicked 反应-单击子元素时防止父元素上的onMouseDown事件 - React - Prevent onMouseDown event on parent element when a child element is clicked click 事件总是在父元素上触发,尽管在子元素上调用了 stopPropation() - click event always fires on parent element, despite stopPropation() having been called on child element 如何仅在单击子项时触发父项单击事件 - How to ONLY trigger parent click event when a child is clicked
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM