菜鸟在线求助focus()问题
我照着书中的例子在写一个BBS。书上有段javascript代码里面用的方法不是很明白。请教各位大侠!
代码如下:
—————————————————————————————————————————————<script Language="JavaScript">
<!--
function isspacestring(mystring)
{
var temp,i,strlen;
temp=true;
strlen=istring.length;
for (i=0;i<=strlen;i++)
{
if ((istring.substring(i,i+1)!=" ")&(temp))
{temp=false;}
}
return temp;
}
function firstisspace(mystring)
{ var istring=mystring;
var temp,i,strlen;
temp=false;
if (istring.substring(0,1)==" ")
{temp=true;}
return temp;
}
function isemail(mystring)
{
var istring=mystring;
var atpos=mystring.indexOf("@");
var temp=true;
if (atpos==-1)
{
temp=false;
}
return temp;
}
function check_input (theForm)
{
if ((theForm.username.value == "")|(firstisspace(theForm.username.value)))
{
alert("请输入用户名,不能以空格开头");
theForm.username.focus();
return (false);
}
if (theForm.username.value.length > 20)
{
alert("用户名的长度应该小于20个字符活数字");
theform.username.focus();
return (false);
}
if (theForm.usernpassword.value == "")|(isspacestring(theForm.userpassword.value)))
{
alert("请输入密码");
theForm.userpassword.focus();
return(false);
}
if (theForm.userpassword.value.length >20)
{
alert("密码的长度应小于20");
theForm.userpassword.focus();
return (false);
}
if (theForm.userpassword.value != theForm.userpassword2.value)
{
alert("两次密码不相同,请重新输入密码");
theForm.userpassword.focus();
return (false);
}
return (true);
}
//-->
</script>
#############################################
问题1。theForm.username.focus(); 这句话所用的 focus()是什么意思它主要是做什么用的啊!!
问题2。
if ((istring.substring(i,i+1)!=" ")&(temp))
上面这句的temp处(&的后面)总事有个大红色的标记,是怎么回事,是不是代码有问题啊!
问题点数:50、回复次数:7Top
1 楼haroyy(天平)回复于 2004-12-03 08:18:39 得分 10
1、意思是光标移到该表单;
2、应该是&&才对吧Top
2 楼bp69(不要偷懒,自强不息)回复于 2004-12-03 08:21:07 得分 10
这句话所用的 focus()是什么意思它主要是做什么用的啊!!----->聚焦到username,表现就是光标跑到username那
Top
3 楼bp69(不要偷懒,自强不息)回复于 2004-12-03 08:22:11 得分 10
if ((istring.substring(i,i+1)!=" ")&&(temp))
Top
4 楼tom2005(随海奔跑)回复于 2004-12-03 09:10:17 得分 10
&是位运算符。&可为位运算,也可为逻辑运算,看情况而定。&&是布尔逻辑运算符。
if ((istring.substring(i,i+1)!=" ")&(temp))
一般用&&
这样应该可以用
Top
5 楼zh_baiyu(SkyBay)回复于 2004-12-03 09:14:51 得分 10
focus是定位光标位置。。。。。。
第二个用 && 来表示“与”Top
6 楼yzw52553(小鹰)回复于 2004-12-03 09:45:53 得分 0
胸闷啊~~~~!
找了好久都没发现在那可以发贴,那位好心的朋友可以帮帮我啊!!
谢了~~~~~~~~~~~~~!Top
7 楼fxy79(石翮)回复于 2004-12-03 20:10:14 得分 0
谢谢了 !!!!!Top




