简体   繁体   中英

jQuery: Prevent scroll to checkbox on label click

When firing a click event on a label $('#someOption label').click(); , the page automatically scrolls to the related checkbox (if it is off the viewport), how can i prevent that?

jsFiddle

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.

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/

除了调用标签的单击之外,为什么不选择复选框呢?

$('#someCheckbox').prop('checked', true);

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