jq select change下拉框選項變化判斷選中值,添加(attr)或移除(removeAttr)一個或多個屬性

select change下拉框選項變化判斷選中值,添加(attr)或移除(removeAttr)一個或多個屬性css

$("#IsRecommend").change(function () {
            var isCheck = $(this).children('option:selected').val();
            if (isCheck == "true") {
                $("#CategoryId").css("display", "");
                $("#FlowId").css("display", "");
                $("#CategoryId").attr({ "isvalid": "yes", "checkexpession": "NotNull" });
            }
            else if (isCheck == "false") {
                $("#CategoryId").css("display", "none");
                $("#FlowId").css("display", "none");
                $("#CategoryId").removeAttr("isvalid checkexpession");
            }
        });


<select id="IsRecommend" name="IsRecommend" style="float:left">
<option value="false">否</option>
<option value="true">是</option>
</select>

removeAttr() 方法從被選元素移除一個或多個屬性this

$(selector).removeAttr(attribute)  //規定要移除的一個或多個屬性。如需移除若干個屬性,請使用 "空格" 分隔屬性名稱。
相關文章
相關標籤/搜索