简体   繁体   中英

Losing selection when clicking checkbox label

I am trying to get a checkbox with a label to function so that when you have text selected in a contenteditable div , clicking on the label will not lose the selection from the div . The label still needs to apply the standard checkbox tick/untick upon clicking it, but keep the focus & selection intack on the div .

Doing a simple focus() on the div won't help as the selection will be gone (and caret is at the beginning). I could of course look into a way for storing the selection object and trying to assign it back after the label click, but isn't there any simpler way of keeping the selection ?

(the reason I need to do this with label & checkbox is because I will be using jQuery UI buttons and I will need the the toggle functionality of them)

On a similar note, if you click the checkbox, you usually still keep the selection in the div , but at least on FF4, if you press the checkbox very frequently (<1s), it will lose the selection. Any idea what's going on there? answered below

example: http://jsfiddle.net/niklasvh/gULM9/

It's a Firefox bug marked 490367.

According to the bug description, double-click functionality on input fields will act unusually when there is a contenteditable div on the page.

I noticed the strange behavior while trying to replicate it manually so I guessed it was a bug. I don't know of any workarounds.

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