JavaScript编制留言簿程序代码第2/3页
更新时间:2008年09月08日 21:07:57 作者:
也许你有一个很酷的主页,很希望与人分享。同时,你希望访问你主页的人能对你的主页提供一些意见和建议,或者你对某个主题感兴趣,而希望客人也许能给你一帮助,这就要用到留言簿。留言簿使得你能与每一个访问你主页的人交换信息。
<HTML>
<HEAD>
<TITLE> 用JavaScript 编 制 留 言 簿 程 序</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
//Someone@abc.com 是 你 自 己 的 电 子 邮 件 地 址
var emailAddress="Someone@abc.com";
function toName()
{
var toNameval=document.forms[0].elements[1].value;
toNameval = "mailto:Someone@abc.com?subject=Guest Book example";
this.document.mail.action = toNameval;
}
function Reset() {
document.forms[0].elements[0].value = "";
document.forms[0].elements[1].value = "";
document.forms[0].elements[2].value =
navigator.appName + " " + navigator.appVersion;
document.forms[0].elements[3].value = "";
document.forms[0].elements[4].value = "";
document.forms[0].elements[5].value = "";
document.forms[0].elements[0].focus();
}
function submitForms() {
if ( (isName() ) && (isEmail()) && (isBrowser())
&& (isCountry()) && (isComment()) && (isFavorite()) )
if (confirm("nYou're about to e-mail the form.nnClick
on YES to submit.nnClick on NO to abort."))
{
alert("nYour submission will now be made to :
nn"+emailAddress+"nnnThank you!");
return true;
}
else
{
alert("nYou have chosen to abort the submission.");
return false;
}
else
return false;
}
function isName() {
var str = document.forms[0].elements[0].value;
if (str == "") {
alert("nThe NAME field is blank.nnPlease enter your name.")
document.forms[0].elements[0].focus();
return false;
}
for (var i = 0; i <str.length; i++)
{
var ch = str.substring(i, i + 1);
if (((ch <"a" || "z" <ch) && (ch <"A" || "Z" <ch)) && ch != ' ')
{
alert("nThe NAME field only accepts letters
& spaces.nnPlease re-enter your name.");
document.forms[0].elements[0].select();
document.forms[0].elements[0].focus();
return false;
}
}
return true;
}
function isEmail()
{
emailAddress=document.forms[0].elements[1].value;
if (document.forms[0].elements[1].value == "") {
alert("nThe E-MAIL field is blank.
nnPlease enter your e-mail address.")
document.forms[0].elements[1].focus();
return false;
}
if (document.forms[0].elements[1].value.indexOf ('@',0) == -1 ||
document.forms[0].elements[1].value.indexOf ('.',0) == -1)
{
alert("nThe E-MAIL field requires a "@" and a "."be used.nnPlease re-enter your e-mail address.")
document.forms[0].elements[1].select();
document.forms[0].elements[1].focus();
return false;
}
else
{
toName();
return true;
}
}
function isBrowser()
{
if (document.forms[0].elements[2].value !
= navigator.appName + " " + navigator.appVersion)
{
if (confirm("nYou've changed your browser
type.nnClick on OK to keep changes.
nnClick on Cancel to restore detected browser."))
return true
else
{
document.forms[0].elements[2].value =
navigator.appName + " " + navigator.appVersion;
return true;
}
}
else
return true;
}
function isCountry() {
var str = document.forms[0].elements[3].value;
if (str == "") {
alert("nThe COUNTRY field is
blank.nnPlease enter your country.")
document.forms[0].elements[3].focus();
return false;
}
for (var i = 0; i <str.length; i++) {
var ch = str.substring(i, i + 1);
if (((ch <"a" || "z" <ch) &&
(ch <"A" || "Z" <ch)) && ch != ' ')
{
alert("nThe COUNTRY field only accepts
letters & spaces.nnPlease re-enter your country.");
document.forms[0].elements[3].select();
document.forms[0].elements[3].focus();
return false;
}
}
return true;
}
function isComment() {
if (document.forms[0].elements[4].value == "") {
if (confirm("nYou're about to submit
without leaving a comment.nnClick
on CANCEL to include a comment.nnClick
on OK to continue without a comment."))
return true
else
{
document.forms[0].elements[4].focus();
return false;
}
}
else
return true
}
最新评论