日期:2014-05-16 浏览次数:20471 次
<html>
<body>
<input id="input" type="text" value="OK, no problem."/>
<input type="button" value="focus" onclick="setFocus('input',true)"/>
<input type="button" value="blur" onclick="setFocus('input',false)"/>
<script type="text/javascript">
function setFocus(id, yes) {
    var obj = document.getElementById(id);
    if (yes) {
        obj.focus();
        obj.value = obj.value;
    } else {
        obj.blur();
    }
}
</script>
</body>
</html>