diff options
author | afc163 <afc163@gmail.com> | 2015-12-12 00:55:14 +0800 |
---|---|---|
committer | afc163 <afc163@gmail.com> | 2015-12-12 00:55:14 +0800 |
commit | 182e9fccc90ae709322b7cc314c8775a9d8d46b8 (patch) | |
tree | 8abc77d6d96667ad26614e47dae3305b3f461f5c /src/util | |
parent | 85a5d3e6e9f0907780b2ed512faaf1c65d246f0d (diff) | |
download | time-picker-182e9fccc90ae709322b7cc314c8775a9d8d46b8.tar.gz time-picker-182e9fccc90ae709322b7cc314c8775a9d8d46b8.tar.zst time-picker-182e9fccc90ae709322b7cc314c8775a9d8d46b8.zip |
select input value range when enter different select panel
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/selection.js | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/util/selection.js b/src/util/selection.js new file mode 100644 index 0000000..395901e --- /dev/null +++ b/src/util/selection.js | |||
@@ -0,0 +1,17 @@ | |||
1 | export default function createSelection(field, start, end) { | ||
2 | if (field.createTextRange) { | ||
3 | const selRange = field.createTextRange(); | ||
4 | selRange.collapse(true); | ||
5 | selRange.moveStart('character', start); | ||
6 | selRange.moveEnd('character', end); | ||
7 | selRange.select(); | ||
8 | field.focus(); | ||
9 | } else if (field.setSelectionRange) { | ||
10 | field.focus(); | ||
11 | field.setSelectionRange(start, end); | ||
12 | } else if (typeof field.selectionStart !== 'undefined') { | ||
13 | field.selectionStart = start; | ||
14 | field.selectionEnd = end; | ||
15 | field.focus(); | ||
16 | } | ||
17 | } | ||