分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

JQuery/JS ?select标签设置默认值、设置禁止选择 button按钮禁止点击

发布时间:2023-09-06 02:24责任编辑:苏小强关键词:暂无标签
//**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、设置禁止选择:**//$("#selectId").attr("disabled", "disabled");$("#selectId").attr("style", "background-color: #EEEEEE;");//设为灰色,看起来更像不能操作的按钮
//**3、按钮禁止点击**//$(‘#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>

JQuery/JS ?select标签设置默认值、设置禁止选择 button按钮禁止点击

原文地址:https://www.cnblogs.com/dyhao/p/10028052.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved