[英]jQuery: Prevent scroll to checkbox on label click
When firing a click event on a label $('#someOption label').click();
在标签
$('#someOption label').click();
上触发点击事件时$('#someOption label').click();
, the page automatically scrolls to the related checkbox (if it is off the viewport), how can i prevent that? ,页面会自动滚动到相关的复选框(如果它不在视口中),我该如何防止呢?
I would try setting the scroll position using jQuery, but my page consists of dynamic elements which means the height of the page is never the same. 我会尝试使用jQuery设置滚动位置,但是我的页面由动态元素组成,这意味着页面的高度永远不会相同。
I think the problem is because you are clicking the label; 我认为问题是因为您正在点击标签; can you click the checkbox element instead, like:
您是否可以单击复选框元素,例如:
$('#someOption input').click();
Demo: http://jsfiddle.net/A7J6J/ 演示: http : //jsfiddle.net/A7J6J/
除了调用标签的单击之外,为什么不选择复选框呢?
$('#someCheckbox').prop('checked', true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.