html中<radio>单选按钮控件标签用法解析及如何设置默认选中

html-css011

html中<radio>单选按钮控件标签用法解析及如何设置默认选中,第1张

方法有两种。

第一种通过<select>的属性来设置选中项,此方法可以在动态语言如php在后台根据需要控制输出结果。

<select  id =  "sel" >

<option  value = "1" >1</ option >

<option  value = "2"  selected = "selected" >2</ option >

<option  value = "3" >3</ option >

</ select > 

第二种为通过前端js来控制选中的项:

<script  type = "text/javascript" >

function change(){

document.getElementById("sel")[2].selected=true

}

</ script >

<select  id =  "sel" >

<option  value = "1" >1</ option >

<option  value = "2" >2</ option >

<option  value = "3" >3</ option >

</ select >

<input  type = "button"  value = "修改"  onclick = "change()"  />

获取<select>标签选中项文本的js代码为:

var  val = document.all.Item.options[document.all.Item.selectedIndex].text

var  i=document.getElementById('sel').options[document.getElementById('sel').selectedIndex].value

扩展资料

Radio 对象代表 HTML 表单中的单选按钮。在 HTML 表单中 <input type="radio">每出现一次,一个 Radio 对象就会被创建。

单选按钮是表示一组互斥选项按钮中的一个。当一个按钮被选中,之前选中的按钮就变为非选中的。当单选按钮被选中或不选中时,该按钮就会触发 onclick 事件句柄。您可通过遍历表单的 elements[] 数组来访问 Radio 对象,或者通过使用 document.getElementById()。

参考资料:百度百科-radio

html常用标签

最近,对html的重温,对一些常用的html标签进行了整理,给大家分享一下。

html结构:

<html> html开始标签

<head>

<title>html文档标题</title>

</head>

<body>

html文档内容....

</body>

</html> html结束标签

html常用标签:

表格:

<table> 表格开始标签

<tr> 行

<td></td> 列

</tr>

</table> 表格结束标签

表格属性:<table width="" height="" border="" bgcolor="" background="" cellpadding="' cellspacing="" >其中: width:为表格的宽度,height:表格的高度,border:表格的边框,

bgcolor表格的背景颜色,background 表格背景颜色。cellpadding:表格字间距, cellspacing:表格边框间距。

双标签:

<b></b>字体加粗

<i></i>斜体

<u></u>字体下划线

<s></s>删除线

<strike></strike>删除线

单标签:

<br />换行

<hr />水平线

空格:

向右双箭头 :»

注册商标符:®

版权符号:©

双引号:"

链接

<a href="#" title="">链接文本/图片</a>

注:# 换成所要链接的文件相对地址。title:为链接提示信息。

图片链接:

<img src="" alt="" width="" hegiht="" >

src:图片链接相对地址,alt:图片信息, width:图片宽度,height:图片高度。

表单:

表单开始标签:<form name="表单名称" method="post/get" action="提交地址">

文本框:<input type="text" name="名称" value="值" />

密码框:<input type="password" name="名称" value="值"/>

单选按钮:<input type="radio" name="名称" checked />

复选框:<input type="checkbox" name="名称" checked />

列表:

<select>

<option value="值"></option>

</select>

文本区域:<textarea cols="文本的宽度" rows="文本行数"></textarea>

提交按钮:<input type="submit" name="名称" value="值" />

重置按钮 <input type="reset" name="名称" value="值" />

表单结束标签:</form>