JQuery/JS select标签动态设置选中值、设置禁止选择 button按钮禁止点击 select获取选中值
//**1、设置选中值:(根据索引确定选中值)**//
var osel=document.getElementById("selID"); //得到select的ID
var opts=osel.getElementsByTagName("option");//得到数组option
var obt=document.getElementById("bt");
obt.onclick=function(){
opts[3].selected=true;//设置option第4个元素,即value="3"为默认选中
}
//**2、通过原生JS来实现设置选中值,(根据value值确定选中值)**// /**
* 设置select控件选中
* @param selectId select的id值
* @param checkValue 选中option的值 //实际情况中可能不是options,而是context,具体自定
*/
function set_select_checked(selID, checkValue){
var select = document.getElementById(selID);
for (var i = 0; i < select.options.length; i++){
if (select.options[i].value == checkValue){
select.options[i].selected = true;
break;
}
}
} //**3、设置禁止选择:**//
$("#selectId").attr("disabled", "disabled");
$("#selectId").attr("style", "background-color: #EEEEEE;");//设为灰色,看起来更像不能操作的按钮 //**4、按钮禁止点击**//
$('#buttonId').attr("disabled", true);
$("#buttonId").attr("style", "background-color: #EEEEEE;");//设为灰色,看起来更像不能操作的按钮
实例:
<!---省略部分代码--->
<tbody>
<tr class="firstRow">
<td valign="top" style="word-break: break-all; width: 20%;" rowspan="1" colspan="1">
<select id="mekeupType" onchange="MekeupTypeChange();">
<option value="moneyWay">货币补偿</option>
<option value="houseWay">房屋补偿</option>
</select>
</td>
<td valign="top" style="word-break: break-all; width: 50%;" rowspan="1" colspan="1">
<input type="button" value="计算" id="buttonCount" onclick="buttonCountClick();" style="background-color: #339999; color: white;border-color: #339999"" />
<input type="button" value="协议打印" id="buttonPoint" onclick="Painting()" style="background-color: #339999; color: white;border-color: #339999""/>
<input type="button" value="签约确认" id="buttonSign" onclick="Sign()" style="background-color: #339999; color: white;border-color: #339999"/>
@*<input type="button" value="返回列表" id="buttonBack" onclick="GoBackList();"/>*@
</td>
<td width="189" valign="top"></td>
<td width="189" valign="top"></td>
<td width="189" valign="top"></td>
<td width="189" valign="top"></td>
</tr>
</tbody>
</table>
<!---省略部分代码---> <script> $(document).ready(function () {
//*****省略部分代码*****//
var mekeupel = document.getElementById("mekeupType"); //得到select的ID
var opts = mekeupel.getElementsByTagName("option");//得到数组option
if (compensationMethod.toLowerCase() == "null") {//null
//null
}
else if (compensationMethod.toLowerCase() == "33c3e03a-3bb6-4147-87bd-4c77b84d615b".toLowerCase()) //货币
{
opts[0].selected = true;//设置option第1个元素
}
else if (compensationMethod.toLowerCase() == "c80ea27b-2d11-4e7d-8d6e-65d2b5210d8a".toLowerCase()) //产权置换
{
opts[1].selected = true;//设置option第1个元素
}
IsSign = parseInt(data[0]["issign"]);
if (1 == IsSign) {
//设置安置补偿方式禁止选择
//disabled="disabled"
//background-color: #EEEEEE;
$("#mekeupType").attr("disabled", "disabled");
$("#mekeupType").attr("style", "background-color: #EEEEEE;");
//设置计算按钮、签约确认按钮 禁止click
$('#buttonCount').attr("disabled", true);
$("#buttonCount").attr("style", "background-color: #EEEEEE;");
$('#buttonSign').attr("disabled", true);
$("#buttonSign").attr("style", "background-color: #EEEEEE;");
} else {
}
//*****省略部分代码*****//
}); </script>
获取select选中值
var select = document.getElementById("HouseType");
var index = select.selectedIndex; // 选中索引
var text = select.options[index].text; // 选中文本
var value = select.options[index].value;//选中值
//document.getElementById("ZSGYTD_HouseInfo.HouseType").value = value;
JQuery/JS select标签动态设置选中值、设置禁止选择 button按钮禁止点击 select获取选中值的更多相关文章
- Jquery chosen动态设置值实例介绍 select Ajax动态加载数据 设置chosen和获取他们选中的值
for (var i = 0; i < obj.length; i++) $("#selectnum" + nid).append("<option myid ...
- JQuery 绑定select标签的onchange事件,弹出选择的值,并实现跳转、传参
<script src="jquery.min.js" type="text/javascript"></script> <scr ...
- JS canvas标签动态绘制图型
使用canvas标签动态绘制图型,当点击鼠标时,以鼠标点击的坐标作为图形中心点.当点击数为偶数时画三角形,当点击数为奇数时画五角星 <!DOCTYPE HTML> <html> ...
- JS 同一标签随机不停切换数据点菜--解决选择困难症
可视化的 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF- ...
- heightcharts点击曲线图获取返回值的问题(ios点击图表第一次无法触发点击事件解决方法)
需求:用的heightcharts插件,点击曲线图想获得所点击点的返回值,如图 问题代码: (function chart_line(){ var data={"title":[& ...
- [Jacky] 解决Ext.Net GridPanel 选择的行数据刷新后不能获取最新值
选择GridPanel中一行数据,当变更数据时并重新刷新之后不能获取最新值,需通过如下方式获取: var internalId = gridPanel.getSelectionModel().getL ...
- jquery/js/a标签实现当前页面跳转的两种方法
在逛购物网站首页时经常看到侧边导航栏,当我们点击导航栏中某一项时会跳转到当前页面的某一处 有两种方法实现,一种是利用js计算好各位置的高度,通过绑定事件使页面跳转到指定位置,另一种是利用a标签进行当前 ...
- 异步渲染页面怎么点击checkbox获取value值
前后端分离时 后端向前端传递json数据 前端根据需要进行页面渲染 因为是异步渲染 想要获取获取渲染数据里面的值时获取不到的 介绍两个方法: 1,设置全局变量 即渲染时在html页面设置全局变量 如 ...
- jQ给下拉框绑定事件,为什么要绑定在框(select标签)上,而不是绑定在选项(option标签)上
这是我在学习锋利的 jquery 书中 5.1.4 的代码时遇到的一个小问题,源代码如下: <head> <style type="text/css"> * ...
随机推荐
- Vue技巧小结(持续更新)
1. 动态生成的input自动focus 背景: input元素在需要时才插入DOM,这时元素用autofocus属性第一次是可以获取焦点,但是如果有第二个,就不再生效,所以得另外的办法. 方法: / ...
- (转)Spring Boot(十六):使用 Jenkins 部署 Spring Boot
http://www.ityouknow.com/springboot/2017/11/11/spring-boot-jenkins.html enkins 是 Devops 神器,本篇文章介绍如何安 ...
- hive复杂类型实战
1.hive 数组简单实践: CREATE TABLE `emp`( `name` string, `emps` array<string>) ROW FORMAT SERDE 'org. ...
- 【转】如何修改 video 样式
我们这里说的“修改 video 样式”并不是要自己实现一套 controls,而是尝试修改 video 的默认样式 隐藏全屏按钮 这个很容易查到 video::-webkit-media-contro ...
- 005_python中的构造函数和析构函数
python中的特殊方法,其中两个,构造函数和析构函数的作用: 比说“__init__”这个构造函数,具有初始化的作用,也就是当该类被实例化的时候就会执行该函数.那么我们就可以把要先初始化的属性放到这 ...
- memcache讲解和在.net中初使用
memcache讲解和在.net中初使用 2017年10月17日 22:51:36 等待临界 阅读数:503 前言 传统数据库面临的问题 数据库死锁 磁盘IO 正文 了解memcache 原理 基 ...
- shut immediate 数据库遭遇 ORA-24324 ORA-24323
SQL> shut immediateORA-24324: service handle not initializedORA-24323: value not allowedORA-27140 ...
- mybatis错误之org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
玩了MyBatis差不多有两年了,中间也玩过MyBatis-Plus,这个MyBatis-Plus其实与MyBatis的区别并不大.今天写博客业务代码的时候,犯一个初学者犯过的错误. 错误信息如下:o ...
- IDEA+控制台使用搜索\查找功能
- 获取数值型数组中大于60的元素个数,给数值型数组中不足60分的加20分。(数组,for循环,if条件判断语句)
package com.Summer_0420.cn; /** * @author Summer * 获取数值型数组中大于60的元素个数 * 给数值型数组中不足60分的加20分 */ public c ...