如果我错了,请纠正我,但无法在脚本标记后面声明变量,以便可以在整个脚本中使用该变量吗?我试过了,我的功能就好像它不在那里一样。我做错了什么,或者这是否应该发生?如果它们完全相同,我不愿意重新声明每个函数的所有变量。如何为多个函数声明变量
对此深感抱歉
<script>
var na=document.getElementById('nr');
var ea=document.getElementById('er');
var em=document.subscribe.email;
var fn=document.subscribe.fname;
var ln=document.subscribe.lname;
var eml=document.subscribe.email.value.length;
var fnl=document.subscribe.fname.value.length;
var lnl=document.subscribe.lname.value.length;
var at=document.subscribe.email.value.indexOf("@");
var per=document.subscribe.email.value.lastIndexOf(".");
function validate_form() {
if((fnl<1 || lnl<1) && !eml<1){
alert("Please enter your first and last name.")
if(fnl<1){fn.focus()}else{ln.focus()}
}
else if((fnl<1 || lnl<1) && eml<1){
alert("Please fill in all fields.")
if(fnl<1){fn.focus()}else{ln.focus()}
}
else if(eml<1 || at<1 || per-at<2 || eml-per<2){
alert("Please enter a valid email address")
em.focus()
}
else if (at>1 && per-at>2 && eml-per>2 && fnl>1 && lnl>1){return true}
vfn(); vln(); vem();
return false}
当瓦尔都在里面的功能它工作完全正常,但是当他们都是这样的,什么都没有发生。
我们猜测没有代码,*总是*发布代码:) – 2010-12-05 09:26:19