select 和 radio 的选中状态
radio:
<script type="text/javascript">
//判断个函数 以上 5 个Radio 那个为选中状态
function judgeRadioClicked()
{
//获得 单选选按钮name集合
var radios = document.getElementsByName("radio_tj");
//根据 name集合长度 遍历name集合
for(var i=0;i<radios.length;i++)
{
//判断那个单选按钮为选中状态
if(radios[i].checked)
{
//弹出选中单选按钮的值
alert(radios[i].value);
}
}
}
</script>
select:
首先可以响应select的onchange事件来调用JS编写的事件响应函数,如<select id="select1" name="select1" onchange="outputSelect();"><option>...</select>
然后编写事件响应函数:
如果select位于表单(form1)中,select的name为select1,则可使用如下方法:
//获得用户选中的项的索引
var index=window.document.form1.select1.selectedIndex;
//根据索引获得该选项的value值
var val=window.document.form1.select1.options[index].value;
如果select并非表单元素,假设select的id为select1,则如下:
var index=window.document.getElementById("select1").selectedIndex;
var val=window.document.getElementById("select1").options[index].value;
如果要输出选择结果,假设HTML中定义了一个<div id="output"></div>,则如下输出:
window.document.getElementById("output").innerText=val;
给出一个我写的示例:
function outputSelect()
{
//获取用户选中的项的索引
var index=window.document.getElementById("select1").selectedIndex;
//根据index获取选中项的value值
var val=window.document.getElementById("select1").options[index].value;
//根据index获取选中项的Text值,即在下拉列表中显示的选项文本
var vname=window.document.getElementById("select1").options[index].text;
//输出value : text
document.getElementById("output").innerText=val+" : "+vname;
}
select 和 radio 的选中状态的更多相关文章
- 改变select组件的option选中状态的快捷方法
以前我都是在<option>标签处通过判断value是否与其中一个相同然后输出selected="selected"来处理的,今天发现可以直接能过Js改变<sel ...
- 设置radio的选中状态
$("#s7").click(function () { var a = document.getElementById("s7"); if (a.checke ...
- [转][html]radio 获取选中状态
方法一: if ($("#checkbox-id").get(0).checked) { // do something } 方法二: if($('#checkbox-id').i ...
- 根据JSON的值设置radio选中状态
说明:页面有一组单选按钮radio,现在页面发送请求得到一组json数据,包括radio的值. 需要根据JSON中的值绑定radio的选中状态> <table class="ta ...
- jquery判断单选按钮radio是否选中的方法
JQuery控制radio选中和不选中方法总结 一.设置选中方法 复制代码代码如下: $("input[name='名字']").get(0).checked=true; $(&q ...
- jquery根据值设置radio和select选中状态
1.radio选中: $("input[name=test][value=34]").attr("checked",true);//value=34的radio ...
- 获取select标签选中状态 的label的值。
<select name="procode" onchange="alert(this.options[this.selectedIndex].text)" ...
- jquery radio取值,checkbox取值,select取值及选中
jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中,及其相关 获取一组radio被选中项的值 var item = $('in ...
- jquery循环遍历radio单选按钮,并设置选中状态
背景:自己在做项目过程中遇到的问题,现在记录一下. 需求:在ajax获取后台数据的之后,需要根据获取的数据对页面中的radio单选按钮进行选中状态设置 因为自身js功底欠佳,所以耽误了点时间,现在把方 ...
随机推荐
- SQL Server 2008连接字符串写法大全
一..NET Framework Data Provider for SQL Server 类型:.NET Framework类库使用:System.Data.SqlClient.SqlConnect ...
- CentOS搭建GitLab服务器
以下为CentOS7下安装GitLab7.4.3的全部流程 1.切换到root用户su root2.下载并安装GitLabcurl -O https://downloads-packages.s3.a ...
- SQL行转列+动态拼接SQL
数据源 Name AreaName qty Specific 叶玲 1 60 1 叶玲 2 1 1 叶玲 6 1 0 叶玲 7 5 0 叶玲 8 1 1 显示效果: Name 1 2 8 ...
- 分表的一个记录---Ruby
sql1=" UPDATE user_red_info_"sql2=" SET status = '#{status}', update_time = '#{update ...
- HDU 3221 Brute-force Algorithm
题意:问funny被调用了多少次,结果ModP,P不一定为质数. 首先很容易发现递推公式fn=fn-1*fn-2;写出前几项a,b,a*b,a*b^2,a^2*b^3,a^3* ...
- mysql压缩包安装配置
1.在环境变量中添加:MYSQL_HOME:C:\05_study\mysql-5.7.10-winx64,在path路径中加入:%MYSQL_HOME%\bin.配置环境变量不是必须的,只是为了能更 ...
- 外国javascript资源搜索
https://www.javascripting.com/search?q=canvas
- iOS高性能设置圆角
自建一个分类可以设置. -(void)cornerImageWithSize:(CGSize)size fillColor:(UIColor *)fillColor completion:(void( ...
- NetSuite SuiteScript 2.0 export data to Excel file(xls)
In NetSuite SuiteScript, We usually do/implement export data to CSV, that's straight forward: Collec ...
- Win10 + Nginx 1.10 + PHP 7 + Redis 配置方法
软件包版本 软件 版本 - 链接 - Nginx nginx-x32-1.10.2.zip 下载 PHP php-7.0.12-nts-Win32-VC14-x64 下载 Redis php_redi ...