js常用功能代碼,js代碼
js常用功能代碼(持續更新):
1---摺疊與展開
<input id="btnDisplay" type="button" class="baocun2" value="添加" onclick="changeDisplay()"/><script type="text/javascript"> function changeDisplay() { var helloDivObj = $("#addressdiv"); var buttonObj = $("#btnDisplay"); var val = buttonObj.attr("value"); if (val == "隱藏") { helloDivObj.hide(); buttonObj.attr("value", "添加"); } else { helloDivObj.show(); buttonObj.attr("value", "隱藏"); } }</script>
2---多選框點擊使文字框可否編輯
<input disabled="disabled" name="telephone" id="tel" class="text" value="123" type="text"><input id="tellphones" value="123" type="hidden"><input checked="true" type="checkbox" onclick="mobile(this)"><label for="mobile_id_flag" style="cursor:pointer"> 與訂單中手機號相同</label><script type="text/javascript"> function mobile(_this) { if (_this.checked) { $("input[id='tel']").val($("#tellphones").val()); $("input[id='tel']").attr("disabled", "disabled"); } else { $("input[id='tel']").val(""); $("input[id='tel']").removeAttr("disabled"); } }</script>