今天我们来学习输入和表单标签。
朋友们,今天我们学习input和form标签。form标签的作用是什么呢?
·它是前端与后端交互的重要工具,用于收集用户信息,并提交给后端存入数据库中。
·form标签有很多种类型,包括文本框、密码框、单选框和多选框等。
·password框是一种特殊的密码框,如果用户在输入时点击回车键,则框内的内容会被隐藏。
2024年11月18日
今天我们来学习输入和表单标签。
朋友们,今天我们学习input和form标签。form标签的作用是什么呢?
·它是前端与后端交互的重要工具,用于收集用户信息,并提交给后端存入数据库中。
·form标签有很多种类型,包括文本框、密码框、单选框和多选框等。
·password框是一种特殊的密码框,如果用户在输入时点击回车键,则框内的内容会被隐藏。
2024年11月18日
控制表单中的单选按钮
<html>
<head>
<title>单选项</title>
<style>
<!--
form{
padding:0px; margin:0px;
font:14px Arial;
}
p{
padding:2px; margin:0px;
}
-->
</style>
<script language="javascript">
function getChoice(){
var oForm = document.forms["myForm1"];
var aChoices = oForm.camera;
for(i=0;i<aChoices.length;i++) //遍历整个单选项表
if(aChoices[i].checked) //如果发现了被选中项则退出
break;
alert("您使用的相机品牌是:"+aChoices[i].value);
}
function setChoice(iNum){
var oForm = document.forms["myForm1"]; //获取表单的节点
oForm.camera[iNum].checked = true; //设置某选项被选中
}
</script>
</head>
<body>
<form method="post" name="myForm1" action="addInfo.php">
您使用的相机品牌:
<p>
<input type="radio" name="camera" id="canon" value="Canon">
<label for="canon">Canon</label>
</p>
<p>
<input type="radio" name="camera" id="nikon" value="Nikon">
<label for="nikon">Nikon</label>
</p>
<p>
<input type="radio" name="camera" id="sony" value="Sony" checked>
<label for="sony">Sony</label>
</p>
<p>
<input type="radio" name="camera" id="olympus" value="Olympus">
<label for="olympus">Olympus</label>
</p>
<p>
<input type="radio" name="camera" id="samsung" value="Samsung">
<label for="samsung">Samsung</label>
</p>
<p>
<input type="radio" name="camera" id="pentax" value="Pentax">
<label for="pentax">Pentax</label>
</p>
<p>
<input type="radio" name="camera" id="others" value="其它">
<label for="others">others</label>
</p>
<p><input type="submit" name="btnSubmit" id="btnSubmit" value="Submit" class="btn"></p>
<p><input type="button" value="检测选中对象" onclick="getChoice();">
<input type="button" value="设置为Canon" onclick="setChoice(0);"></p>
</form>
</body>
</html>