文本框脚本_取得文本_跨浏览器_P421
一、取得_用户在文本框中选择的文本
文本框脚本_取得选择的文本
Select some text in the textbox.
二、取得_文本框中部分文本
Select some text in the textbox.
(function(){
function selectText(textbox, startIndex, stopIndex){
if (textbox.setSelectionRange){
textbox.setSelectionRange(startIndex, stopIndex);
} else if (textbox.createTextRange){
var range = textbox.createTextRange();
range.collapse(true);
range.moveStart("character", startIndex);
range.moveEnd("character", stopIndex - startIndex);
range.select();
}
textbox.focus();
}
var btn = document.getElementById("select-btn");
EventUtil.addHandler(btn, "click", function(event){
var textbox = document.forms[0].elements[0];
selectText(textbox, 4, 7);
});
})();