蓝森林首页 | 返回主页 | 本站地图 | 站内搜索 | 联系信箱 |
 您目前的位置:首页 > 自由软件 > 技术交流 > 应用编程


    

蓝森林 http://www.lslnet.com 2006年8月25日 8:28

js 求助:怎么在当前页面打印一个字符串?

页面代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="" onSubmit="">
  <p>
    <input type="text" name="textfield" />
  *</p>
  <p>
    <input type="submit" name="Submit" value="提交" />
  </p>
</form>
</body>
</html>

刚开始载入页面的时候,不显示*
点击提交,判断 input 是否为空,如果为空,那么页面不提交,还是原来的页面,只是刷新了一下,显示那个 * ;
如果不为空,直接提交

// 就像“我佛山人的那个 validator 一样” ,只是 1.5 版本,不能只验证是否为空

js  不懂啊,请叫高人给指点一下,谢谢啦

[html]
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 2</title>
<script language=javascript>
function check() {
    if(!document.form1.textfield.value){
      document.getElementById("sign").style.display="";
      return false;
  }
     return true;

}
</script>
</head>

<body>
<form id="form1" name="form1" method="post" action="" onSubmit="return check()">
  <p>
    <input type="text" name="textfield"/>
<span style="display:none" id="sign"> *</span></p>
  <p>
    <input type="submit" name="Submit" value="提交" />
  </p>
</form>

</body>
</html>
[/html]


回复 #2 asfman 的帖子

谢谢!

正是我想要的结果!




Copyright © 1999-2000 LSLNET.COM. All rights reserved. 蓝森林网站 版权所有。 E-mail : webmaster@lslnet.com