权威指南 18-1

来源:互联网 发布:php成绩管理系统代码 编辑:程序博客网 时间:2024/04/29 22:43

<!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=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form name="everything">
<table border="border" cellpadding="5">
<tr>
<td>Username:<br />[1]<input type="text" name="username" size="15" /></td>
<td>Password:<br />[2]<input type="password" name="password" size="15" /></td>
<td rowspan="4" >
Input Events[3]:<br /><textarea name="textarea" rows="20" cols="28"></textarea></td>
<td rowspan="4" align="center" valign="center">
[9]<input type="button" value="Clear" name="clearbutton" /><br />
[10]<input type="submit" value="Submit"name="submitbutton" /><br />
[11]<input type="reset" value="Reset" name="resetbutton" /></td>
</tr>
<tr> <td colspan="2">
Filename:[4]<input type="file" name="file" size="15"/></td>
</tr>
<tr><td>My Computer Peripherals:<br />
[5]<input type="checkbox" name="extras" value="burner" checked="checked" />DVD Writer <br />
[5]<input type="checkbox" name="extras" value="printer" />Printer <br />
[5]<input type="checkbox" name="extras" value="card" />Card Reader </td>
<td>My Web Browser:<br />
[6]<input type="radio" name="browser" value="ff" checked="checked" />Firebow<br />
[6]<input type="radio" name="browser" value="ie" />Internet Explorer<br />
[6]<input type="radio" name="browser" value="other"/>Other
</td>
</tr>
<tr><td>My Hobbies:[7]<br />
<select multiple="multiple" name="hobbies" size="4">
<option value="programming">Hacking JavaScript</option>
<option value="surfing" >Surfing the web</option>
<option value="caffeine">Drinking coffee</option>
<option value="annoying">Annoying my Friends</option>
</select></td>

<td align="center" valign="center"> My Favorite Color:<br />[8]<select name="color">
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
<option value="white">White</option></select>
</td></tr>
</table>
</form>
<div align="center">
<table border="4" bgcolor="#FFC0CB" cellpadding="4" cellspacing="1">
<tr>
<td align="center"><b>Form Elements</b></td>
<td>[1] Text </td><td>[2] Password</td> <td>[3] Textarea</td>
<td>[4] Fileu</td> <td>[5] Checkbox</td></tr>
<tr>
<td>[6] Radio</td> <td>[7] Select (list)</td>
<td>[8] Select (menu)</td> <td>[9] Button</td>
<td>[10] Submit</td><td>[11] Reset</td>
</tr>
</table>
</div>
<script>
function report(element,event){
if(element.type=="select-one"||element.type=="select-multiple"){
value =" "//这个是干什么的?
for(var i=0;i<element.options/*记住这里是options不是elementss*/.length;i++)
if(element.option[i].checked)
value += element.option[i].value+" "/*这里为什么会有一个小空格??*/;
}
else if(element.type == "textarea") value="..."
else value = element.value;

var msg= event +":"+ element.name+'('+value+')/n';//这里最好不要用this 因为在事件处理函数的时候用this作为事件发生元素的引用
var t = element.form.textarea;
t.value = t.value + msg;
}

function addhandlers(f)
{
for(var i=0;i<f.elements.length;i++){
var e=f.elements[i];
e.onclick = function(){ report(this/*这里面的this就是e的引用了!!*/,'Click');}
e.onchange = function(){ report(this,'Change');}
e.onfocus = function() {report(this, 'Focus');}
e.onblur = function() { report(this,'Blur');}
e.onselect = function() { report (this,'Select');}
}
f.clearbutton.onclick = function (){
this.form.textarea.value='';report(this,'Click');
}
f.submitbutton.onclick = function(){
report(this,'Click');return false;
}
f.resetbutton.onclick = function () {
this.form.reset(); report(this,'Click'); return false;
}
}
addhandlers(document.everything);
</script>







</body>
</html>

 

原创粉丝点击