document.execCommand('selectAll');. , , /.
, :
function trySelect(el, evenInactive, select_ios) {
var select = function() {
try {
if (mojo.isTouch && select_ios && core.iosDevice && mojo.isInput(el) && document.execCommand) {
document.execCommand('selectAll');
} else {
el.select();
}
} catch (e) {
}
};
if (el && el.select && !el.disabled && (!el.readOnly || el.selectReadOnly) && mojo.isInput(el)) {
if (evenInactive || mojo.activeElement() === el) {
if (mojo.isTouch && core.webkitVer) {
setTimeout(select, 0);
} else {
select();
}
}
}
}
:
- mojo.isTouch - true
- core.iosDevice - true iOS
- mojo.isInput - tests for an input element
- mojo.activeElement () - document.activeElement
edit: document.execCommand('selectAll');should not be used and el.setSelectionRange(0, el.value.length);used instead. This seems to work fine on iOS5 ... It may not work on iOS4 (I don't have an iOS4 device to test).
source
share