设置只读

// 设置只读
function SetReadOnly(jObj) {
    if (jObj.children().length > 0) {
        jObj.find("input,textarea").each(function () {
            var that = $(this);
            that.prop("readonly", true)
            .css("background-color", "#EBEBE4");
            if (that.hasClass("datepicker")) {
                that.datepicker("destroy")
            }
        })
        jObj.find("select").each(function () {
            $(this).bind("focus", function (e) {
                this.defaultIndex = this.selectedIndex;
            })
            .bind("change", function (e) {
                this.selectedIndex = this.defaultIndex;
                e.preventDefault();
            })
           .css("background-color", "#EBEBE4")
           .attr("readonly", "readonly");
        });
    } else {
        jObj.prop("readonly", true)
            .css("background-color", "#EBEBE4");
    }
}

 

posted @ 2016-07-06 14:41  江—城—子  阅读(120)  评论(0编辑  收藏  举报