1. 程式人生 > >JQuery/JS select標簽設置默認值、設置禁止選擇 button按鈕禁止點擊

JQuery/JS select標簽設置默認值、設置禁止選擇 button按鈕禁止點擊

var input val cas script func pts nbsp idt

//**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按鈕禁止點擊