//**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>
&nbsp; &nbsp;&nbsp;
</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"" />&nbsp; &nbsp;&nbsp;
<input type="button" value="协议打印" id="buttonPoint" onclick="Painting()" style="background-color: #339999; color: white;border-color: #339999""/>&nbsp; &nbsp;&nbsp;
<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;

select用法拓展阅读:select用法大全

JQuery/JS select标签动态设置选中值、设置禁止选择 button按钮禁止点击 select获取选中值的更多相关文章

  1. Jquery chosen动态设置值实例介绍 select Ajax动态加载数据 设置chosen和获取他们选中的值

    for (var i = 0; i < obj.length; i++) $("#selectnum" + nid).append("<option myid ...

  2. JQuery 绑定select标签的onchange事件,弹出选择的值,并实现跳转、传参

    <script src="jquery.min.js" type="text/javascript"></script> <scr ...

  3. JS canvas标签动态绘制图型

    使用canvas标签动态绘制图型,当点击鼠标时,以鼠标点击的坐标作为图形中心点.当点击数为偶数时画三角形,当点击数为奇数时画五角星 <!DOCTYPE HTML> <html> ...

  4. JS 同一标签随机不停切换数据点菜--解决选择困难症

    可视化的 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF- ...

  5. heightcharts点击曲线图获取返回值的问题(ios点击图表第一次无法触发点击事件解决方法)

    需求:用的heightcharts插件,点击曲线图想获得所点击点的返回值,如图 问题代码: (function chart_line(){ var data={"title":[& ...

  6. [Jacky] 解决Ext.Net GridPanel 选择的行数据刷新后不能获取最新值

    选择GridPanel中一行数据,当变更数据时并重新刷新之后不能获取最新值,需通过如下方式获取: var internalId = gridPanel.getSelectionModel().getL ...

  7. jquery/js/a标签实现当前页面跳转的两种方法

    在逛购物网站首页时经常看到侧边导航栏,当我们点击导航栏中某一项时会跳转到当前页面的某一处 有两种方法实现,一种是利用js计算好各位置的高度,通过绑定事件使页面跳转到指定位置,另一种是利用a标签进行当前 ...

  8. 异步渲染页面怎么点击checkbox获取value值

    前后端分离时 后端向前端传递json数据  前端根据需要进行页面渲染 因为是异步渲染 想要获取获取渲染数据里面的值时获取不到的 介绍两个方法: 1,设置全局变量 即渲染时在html页面设置全局变量 如 ...

  9. jQ给下拉框绑定事件,为什么要绑定在框(select标签)上,而不是绑定在选项(option标签)上

    这是我在学习锋利的 jquery 书中 5.1.4 的代码时遇到的一个小问题,源代码如下: <head> <style type="text/css"> * ...

随机推荐

  1. 解决Go依赖包安装问题

    最近在学习Go编写后端服务,先放出谢大的书镇楼: https://github.com/astaxie/build-web-application-with-golang/blob/master/zh ...

  2. win10 激活(亲测可用)

    转自http://www.ylmfwin100.com/ylmf/8643.html 1.以管理员身份运行命令行(这一步一定要做) 2.依次输入以下命令 slmgr.vbs /upk (此时弹出窗口显 ...

  3. 5.03-requests_ssl

    import requests url = 'https://www.12306.cn/mormhweb/' headers = { 'User-Agent': 'Mozilla/5.0 (Macin ...

  4. 机器学习算法总结(三)——集成学习(Adaboost、RandomForest)

    1.集成学习概述 集成学习算法可以说是现在最火爆的机器学习算法,参加过Kaggle比赛的同学应该都领略过集成算法的强大.集成算法本身不是一个单独的机器学习算法,而是通过将基于其他的机器学习算法构建多个 ...

  5. go第三方日志系统-seelog-Basic sections

    https://github.com/cihub/seelog 文档学习:https://github.com/cihub/seelog/wiki 1.安装: go get github.com/ci ...

  6. 深入理解mongodb查询条件语句

    阅读目录 1. 理解:"$lt"."$lte"."$gt" 和 "$gte" 2. 理解 '$ne' 3. 理解 &qu ...

  7. Python脱产8期 Day07 2019/4/19

    一 数据类型的相互转化 1.哪些类型可以转换为数字类型 2.数字转换为字符串 print(str(10)) 3.字符串与列表相互转换 1.字符串转化为列表:list(字符串) 2.列表转换为字符串:' ...

  8. 2018Action Recognition from Skeleton Data via Analogical Generalization over Qualitative Representations

    论文标题: 来源/作者机构情况: Northwestern University Thirty-Second AAAI Conference on Artificial Intelligence, 2 ...

  9. C学习笔记-一些知识

    memset可以方便的清空一个结构类型的变量或数组. 如: struct sample_struct { ]; int iSeq; int iType; }; 对于变量 struct sample_s ...

  10. Clustering[Evaluation]

    0. 背景 评估(或者说验证)聚类结果就如同聚类本身一样困难.通常的方法有内部评估和外部评估这两种: 内部评估的方法:通过一个单一的量化得分来评估算法好坏:该类型的方法 外部评估的方法:通过将聚类结果 ...