function validate(id){
var temp=document.addForm.id.value;
window.alert(temp);
if(temp==""){
window.alert("不能为空");
}
}通过onblur把text的name传进去但是。为什么temp不能取得值
var temp=document.addForm.id.value;
window.alert(temp);
if(temp==""){
window.alert("不能为空");
}
}通过onblur把text的name传进去但是。为什么temp不能取得值
<script>
function validate(id){
var temp=document.addForm.elements[id].value;
window.alert(temp);
if(temp==""){
window.alert("不能为空");
}
}
</script>
<form name="addForm">
<input type="text" name="xx" onblur="validate(this.name)">
</form>
<script>
function validate(s){
if(s==""){
window.alert("不能为空");
}
}
</script>
<form name="addForm">
<input type="text" name="xx" onblur="validate(this.value)">
</form>
function validate(id){
var temp=document.addForm.elements[id].value; //document.getElementById(id).value;换成这句也可以
window.alert(temp);
if(temp==""){
window.alert("不能为空");
}
}
</script>
<form name="addForm">
<input type="text" name="xx" onblur="validate(this.name)">
</form>这样就可以了,因为你传进来的参数为字符串,
var temp=eval("document.addForm." + id + ".value");
window.alert(temp);
if(temp==""){
window.alert("不能为空");
}
}