代码
function selectElementContents(el) {
var range = document.createRange();
range.selectNodeContents(el);
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
}
var foo = function(){
var el = document.getElementById("hello");
selectElementContents(el);
}