在文本框中输入,在文本区域中输出
2010-3-6 杜世伟 JavaScript
<!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>
<script type="text/javascript" language="javascript">
function checkmsg(){
var name = document.getElementById("name").value;
if(name==""){
alert("请输入您的姓名!");
document.form1.name.focus();
return false;
}
if(name.length >8){
alert("姓名不能超过8个字符!");
name = name.substring(0,8);
//document.getElementById("test").value = str.substring(0,8);test是它的type值,而这个地方应该是name值
//document.getElementById("name").value = str.substring(0,8);
return false;
}
var age=document.getElementById("age").value;
//if(document.form1.age.value==""){
if(age==""){
alert("请输入您的年龄!");
document.form1.age.focus();
return false;
}
document.form1.textarea.value="姓名:"+name+"\n年龄:"+age+"\n"+choices();
}
function choices(){
f=document.forms[0];
str1="",str2="",str3="";
for(i=0;i<f.sex.length;i++){
if(f.sex[i].checked){
str1="性别:"+f.sex[i].value+"";
}
}
for(i=0;i<f.favorite.length;i++){
if(f.favorite[i].checked){
str2="爱好:"+f.favorite[i].value+"";
}
}
sel = document.forms[0].select
str3 = sel.options[sel.selectedIndex].text
return str=str1+"\n"+str2+"\n所在城市:"+str3;
}
</script>
</head>
<body bgcolor="#99FFCC">
<form id="form1" name="form1" method="post" action="">
<table width="453" align="center" bgcolor="#FFFF99">
<tr>
<td width="92">姓名:</td>
<td width="349"><label>
<input type="text" name="name" id="name"/>
</label></td>
</tr>
<tr>
<td>性别:</td>
<td><label>
<input type="radio" name="sex" checked="checked" value="男"/>男
</label>
<label>
<input type="radio" name="sex" value="女"/>女
</label></td>
</tr>
<tr>
<td>年龄:</td>
<td><label>
<input type="text" name="age" id="age"/>
</label></td>
</tr>
<tr>
<td>爱好;</td>
<td><label>
<input type="checkbox" name="favorite" value="上网" checked="checked"/>上网
</label>
<label>
<input type="checkbox" name="favorite" value="旅游" />旅游
</label>
<label>
<input type="checkbox" name="favorite" value="打电脑" />打电脑
</label>
<label>
<input type="checkbox" name="favorite" value="看书" />看书
</label></td>
</tr>
<tr>
<td>所在城市</td>
<td><label>
<select name="select">
<option>南阳</option>
<option>信阳</option>
<option>商丘</option>
<option>郑州</option>
</select>
</label></td>
</tr>
<tr>
<td> </td>
<td><input type="button" name="submit" value="提交" onclick="checkmsg()"/>
<input type="reset" value="重置" /></td>
</tr>
<tr>
<td>显示信息框:</td>
<td><label>
<textarea name="textarea" cols="20" rows="10" id="a"></textarea>
</label></td>
</tr>
</table>
</form>
</body>
</html>
热门日志
分类
- Django(4)
- ssdb(1)
- Mac(7)
- C(1)
- memcache(1)
- Python(32)
- Vim(8)
- sed(2)
- ansible(3)
- awk(4)
- shell(3)
- about(1)
- git(9)
- bat(4)
- svn(0)
- docker(1)
- Tornado(1)
- go(2)
- 架构(18)
- Vue(1)
- game(2)
- Html(6)
- Java(8)
- Mysql(37)
- Ajax(2)
- Jsp(1)
- Struts(8)
- Linux(72)
- JavaScript(39)
- Staruml(0)
- Mouth(1)
- Php(102)
- Windows(8)
- Message(48)
- Lua(10)
- Compute(1)
- Redis(7)
- Nginx(12)
- Jquery(1)
- Apache(1)
- cocos2d-x(8)