就是想选中文本框时让 文字选中 为什么放在window.onload里面就不行 放在外面才可以?
<!DOCTYPE html>
<html>
<head>
<title></title>
<script language="javascript" type="text/javascript">
window.onload=function(){
function getFocus() {
document.getElementById("test").select();
}
}
</script>
</head>
<body>
<form id="f1">
<input type="text" id="test" name="test" value="你好嗎?" onfocus="getFocus();"/>
<button type="submit">aaa</button>
</form>
</body>
</html>
写在window.onload=function(){}里面,外面无法访问到,其实你要想写在里面,你可以在js里面获取元素,然后添加
focus
事件。