<html>
<head>
<script language="javascript">
function addEvent() {
var ele = document.getElementById("text");
ele.onblur=function(){alert();}
}
</script>
</head>
<body>
<input type="text" id="text" value="0">
<input type="button" name="add" value="加入事件" onclick="addEvent()">
</body>
</html>1. getElementById 取的是obj的id而非name
2. onblur 在JS代码写时注意大小写
<head>
<script language="javascript">
function addEvent() {
var ele = document.getElementById("text");
ele.onblur=function(){alert();}
}
</script>
</head>
<body>
<input type="text" id="text" value="0">
<input type="button" name="add" value="加入事件" onclick="addEvent()">
</body>
</html>1. getElementById 取的是obj的id而非name
2. onblur 在JS代码写时注意大小写
但我还是不清楚,ele.onClick=new Function("alert();"); 也能好使.
<head>
<script language="javascript">
function addEvent() {
var ele = document.getElementById("text");
ele.attachEvent("onblur",function (){ ele.value="已经blur了!";});
//ele.onBlur=new Function("alert();");
}
</script>
</head>
<body>
<input type="text" id="text" value="0" onFocus="this.value=''">
<input type="button" name="add" value="加入事件" onclick="addEvent()">
</body>
</html>