17.4.htm

来自「精通JavaScript动态网页编程(书)」· HTM 代码 · 共 56 行

HTM
56
字号
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Textfield Test</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
</head>
<body>
<h2 align="center">测试表单</h2>
<form name="testform" id="testform" 
      action="http://www.javascriptref.com" method="get">
<label>文本域 1: <input type="text" name="text1" id="text1" size="20"
               value="初始值"></label>
<br>
<label>文本域 2: <input type="text" name="text2" id="text2" size="20"
               maxlength="20"></label>
<p>
<input type="button" value="检测值"
       onclick="alert(document.testform.text1.value);">

<input type="button" value="设置值"  
  onclick="document.testform.text1.value=document.testform.text2.value;"
><p>

<input type="button" value="“禁用”触发器"
onclick="document.testform.text1.disabled=!(document.testform.text1.disabled
);">

<input type="button" value="“只读”触发器"
onclick="document.testform.text1.readOnly=!(document.testform.text1.readOnly
);"><p>

<input type="button" value="获得焦点"         
       onclick="document.testform.text1.focus();">
<input type="button" value="失去焦点" 
       onclick="document.testform.text1.blur();"><p>
<input type="button" value="选择 文本域 1" 
       onclick="document.testform.text1.select();">
</form>

<hr>
<h2 align="center">公用域属性</h2>
<script type="text/javascript">
<!-- 
   document.write("defaultValue: " + document.testform.text1.defaultValue+"<br>");
   document.write("form: "+document.testform.text1.form+"<br>");
   document.write("form.name: " + document.testform.text1.form.name+
"<br>");
   document.write("name: "+document.testform.text1.name+"<br>");
   document.write("type: "+document.testform.text1.type+"<br>");
   document.write("value: "+document.testform.text1.value+"<br>");
//-->
</script>
</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?