//表单填充
表单填充
, formDataLoad: function (domId, obj) {
for (var property in obj) {
if (obj.hasOwnProperty(property) == true) {
if ($("#" + domId + " [name='" + property + "']").size() > 0) {
$("#" + domId + " [name='" + property + "']").each(function () {
var dom = this;
if ($(dom).attr("type") == "radio") {
$(dom).filter("[value='" + obj[property] + "']").attr("checked", true);
}
if ($(dom).attr("type") == "checkbox") {
obj[property] == true ? $(dom).attr("checked", "checked") : $(dom).attr("checked", "checked").removeAttr("checked");
}
if ($(dom).attr("type") == "text" || $(dom).prop("tagName") == "SELECT" || $(dom).attr("type") == "hidden" || $(dom).attr("type") == "textarea") {
$(dom).val(obj[property]);
}
if ($(dom).prop("tagName") == "TEXTAREA") {
$(dom).val(obj[property]);
}
});
}
}
}
}
// 绑定单个下拉框方法
, bindSelectSingle: function (domId, data, defaultVal) {
/// <summary>
/// 绑定下拉框方法
/// </summary>
/// <param name="domId" type="type">dom的ID</param>
/// <param name="data" type="type">json数据</param>
var selectDom$ = $("#" + domId);
selectDom$.find("option").remove();
$(data).each(function () {
selectDom$.append("<option value='" + this.Key + "'>" + this.Value + "</option>");
});
if (defaultVal != undefined) {
selectDom$.val(defaultVal);
}
}
//取url参数
getUrlVars: function () {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,
function (m, key, value) {
vars[key] = value;
}
);
return vars;
}
, getValueBydataPropAndKey: function (dataProp, key) {
/// <summary>
/// 通过数据源属性和下拉框Key得到Value
/// </summary>
/// <param name="dataProp" type="string">数据源属性</param>
/// <param name="key" type="string">下拉框Key</param>
var json = window.cacheSelectData
, arr = JSON.parse(json[dataProp])
, value = "";
$(arr).each(function () {
if (this.Key == key) {
value = this.Value;
return;
}
});
return value;
}
//脏值处理
, dirtyValueHandle: function (val) {
if (val == null || val == undefined) {
return "";
} else {
return val;
}
}
//url参数转对象,如?name=1&age=20转换后为{name:1,age:20}
, parseQuery: function (query) {
var reg = /([^=&s]+)[=s]*([^&s]*)/g;
var obj = {};
while (reg.exec(query)) {
obj[RegExp.$1] = RegExp.$2;
}
return obj;
}