暖暖环游世界学者:最最最基础的javascript,还是有些问题。。。2

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/29 06:48:38
<body>

<p align="center"><font color="black" size="20">新用户注册</font></p>
<br><br><br>

<form name="form1" method="POST" action="">

<p align="center">
User Name: <input type="text" name="user" value="">
<font color="red" size="5">*</font><br><br>

<p align="center">
User Password: <input type="password" name="password" value="">
<font color="red" size="5">*</font><br><br>

<p align="center">
Again Password: <input type="password" name="apassword" value="">
<font color="red" size="5">*</font><br><br>

<p align="center">
E-Mail: <input type="text" name="mail" value="">
<font color="red" size="5">*</font><br><br>

<p align="center">
HomePage: <input type="text" name="homepage" value=""><br><br>

<p align="center">
OICQ: <input type="text" name="Oicq" value="">
<font color="red" size="5">*</font><br><br>

<p align="center">
<input type="reset" name="again_input" value="reset">
<input type="submit" name="Submit" value="send" onclick="yonghuming() , mima(form1.password.value) , chongfu(form1.apassword.value,form1.password.value) , email(form1.mail.value) , QQ(form1.Oicq.value);">
<!-- 问题1:-->
</form>

</body>
</html>

刚学javascript,我想用它来判断用户注册信息。但有些东西不太明白。

问题1: <input type="submit" name="Submit" value="send" onclick="yonghuming() , mima(form1.password.value) , chongfu(form1.apassword.value,form1.password.value) , email(form1.mail.value) , QQ(form1.Oicq.value);">
我把onclick都放到提交按钮上了,但这行是在太长了,看着头晕。。如何放在定义各个组建后面,比如
User Name: <input type="text" name="user" value="" onclick="yonghuming();"> 但这么写我试过不行。。。

问题2: 我想让用户输入密码只能为数字0-9,不能为字母,如何去写,上面那个不成。。。

问题3: if((email.indexOf('@',0) == -1) || (email.indexOf('.',0) == -1))
这个要表达的意思我能明白,是说E-mail中必须有@和.这两个符吧。不过这么写不是很明白。。参数后面那个0是作什么的?

偶打的很乱。。。说实话,自己看着头都晕……真是难为大家了。。。麻烦大家不忙的时候看看。解答解答。

ps:发现JavaScript做这个挺方便的。嘎嘎,另外,为什么偶家电脑,只要在JavaScript或者Jsp中用中文,就全都是乱码呢。。~~~

一个发不下。。这个是第2部分。。1在
http://zhidao.baidu.com/question/745153.html

可能我的能力不够!第一个问题里面的onclick="yonghuming() , mima(form1.password.value) , chongfu(form1.apassword.value,form1.password.value) , email(form1.mail.value) , QQ(form1.Oicq.value);">我看不明白(是不是应该是yonghuming(); mima(form1.password.value) ;)
第二个问题
if (isNaN(form1.password.value))
{
alert("请输入数字!");
return false;
}
第三个问题
那个0是说搜索字符中变量的第0个字开始搜索!
indexOf 方法
返回 String 对象内第一次出现子字符串的字符位置。

strObj.indexOf(subString[, startIndex])

参数
strObj

必选项。String 对象或文字。

subString

必选项。要在 String 对象中查找的子字符串。

starIndex

可选项。该整数值指出在 String 对象内开始查找的索引。如果省略,则从字符串的开始处查找。

答问题1:写个函数如check()
在form的<form action="处理页面" name="myform" onsubmit="return check()">
答问题2:<input type=text onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')">这样在输入或粘贴时不是数字的值将自动消除
答问题3:可以用正则表达式来判断是不是email
function isemail (s)//验证E-MAIL格式函数
{

if (s.length > 100)
{
window.alert("email地址长度不能超过100位!");
return false;
}

var regu = "^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|NET|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT)$"
var re = new RegExp(regu);
if (s.search(re) != -1) {
return true;
} else {
window.alert ("请输入有效合法的E-mail地址 !")
return false;
}
}
另外
String.indexOf("@",0),0 的意思:可选的整数值,指出在 String 对象内开始查找的索引。如果省略,则从字符串的开始处查找。

jsp中默认字符集不是中文
你可以到http://www.javafan.net/article/20041119155503247.html看如何解决