表单文本框中文本的获取,还有当前时间的显示
2010-07-08 21:45
477 查看
1. 以下是获取表单文本框中的内容例子:
str[0]= document.all.cnlTest1.value; //用第一种方法获得文本框中输入的内容
str[1]= document.all["cnlTest2"].value; //用第二种方法获得文本框中输入的内容
str[2]=document.all.tags('form')[0].cnlTest3.value;//用第三种方法获得文本框中输入的内容
2. 另外一种直接根据ID号去获取文本值:
var text = document.getElementById("password");
alert("password is " + text.value);
3. 显示系统当前时间:
str[0]= document.all.cnlTest1.value; //用第一种方法获得文本框中输入的内容
str[1]= document.all["cnlTest2"].value; //用第二种方法获得文本框中输入的内容
str[2]=document.all.tags('form')[0].cnlTest3.value;//用第三种方法获得文本框中输入的内容
<mce:script language="javascript"><!-- function Value() { var str=new Array(3); str[0]= document.all.cnlTest1.value; //用第一种方法获得文本框中输入的内容 str[1]= document.all["cnlTest2"].value; //用第二种方法获得文本框中输入的内容 str[2]=document.all.tags('form')[0].cnlTest3.value;//用第三种方法获得文本框中输入的内容 with(document) //访问document对象的属性值 { write("姓名:"+str[0]+"<br>"); writeln("住址:"+str[1]+"<br>"); writeln("工号:"+str[2]+"<br>"); } } // --></mce:script> </head> <body> <form action="" method="get" name="form1"> <p> </p> <p>姓名: <input id="cnlTest1" name="cnlTest1" value=""> </p> <p> 住址: <input id="cnlTest2" name="cnlTest2" value=""> </p> <p> 工号: <input id="cnlTest3" name="cnlTest3" value=""> </p> <p> <input name="" type="Submit" onClick="Value()" value="显示信息"> </p> </form> </body>
2. 另外一种直接根据ID号去获取文本值:
var text = document.getElementById("password");
alert("password is " + text.value);
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'getObject.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css" mce_href="styles.css"> --> </head> <mce:script type="text/javascript"><!-- function show(){ //var text = form1.textfield.value; var text = document.getElementById("password"); alert("password is " + text.value); var text1 =document.all.text.value; alert("text1 is " + text1); } function println(str) { document.write(str); } // --></mce:script> <body id="body"> <form id="form1" name="form1" method="post" action=""> <label> 姓名: <input type="text" id="text" name="textfield" /> </label> <p> <label> 密码: <input type="password" id="password" name="textfield2" /> </label> <p> <p> <label> <% //内容: //<input type="text" id="content" name="content" onChange="println(this.value)"/> %> </label> <p> <input type="submit" name="Submit" value="查看密码和姓名" onclick="show()" /> </p> </form> </body> </html>
3. 显示系统当前时间:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'blurfocus.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css" mce_href="styles.css"> --> </head> <mce:script type="text/javascript"><!-- function show(str) { if(str.length>4) { alert("大于4"); } else { alert("小于4"); } } function showTime() { var date = new Date(); form1.name.value = date.toLocaleString(); } function myFun() { setInterval("showTime()",1000); } // --></mce:script> <body onLoad="myFun()"> <form id="form1" name="form1"> sName: <input type="text" id="name" name="name" onBlur="show(this.value)"></input> </form> </body> </html>
相关文章推荐
- VC++获取系统当前时间并显示
- IOS---如何获取当前的日期和时间(阴历阳历),并显示带阴历阳历24节气的日历
- 文本框特效:获取焦点时自动清除默认文本 失去焦点重新显示默认文字
- 获取Spinner当前显示的文本内容
- js获取当前时间显示在页面上并每秒刷新
- js实时获取并显示当前时间的方法
- js获取当前时间显示在页面上
- JS简单获取及显示当前时间的方法
- iOS 获取当前时间,并按照要求格式显示
- HTML中让表单input等文本框为只读不可编辑但可以获取value值的方法;让文本域前面的内容显示在左上角,居中
- js获取当前时间显示
- 通过html()的方法获取文本内容, form表单组件显示的值与获取到的值不一致的问题
- WINCE应用层设计经验总结-关于当前时间显示和当前时间获取
- JavaScript获取当前时间并动态显示
- 判断手机号的输入是否正确、获取当前的时间以及显示距离上次发布有多久的时间
- QTime获取当前时间,QDateTime获取日期和时间,QTimer定时器,QLCDNumber数码显示框
- 获取当前时间并显示在网页上
- JS(截取字符串,显示当前系统时间yyyy-MM-dd,从文本框得到的数值计算)
- 当前时间到固定日期的天数,如:在页面弹出显示到到2015年5月1日还有多少天
- 使用jQuery制作高级炫酷吊炸天表单,页面加载完成文本框获得焦点,文本框设置默认文本,文本字数动态显示.....