JS判断控件类型和设置控件的值 - 初稿(未考虑checkboxlist等控件)
2017-06-03 11:06:31 访问(1695) 赞(0) 踩(0)
function SetCtrlValue8This(cThis, theValue) {
// JS判断控件类型和设置控件的值 - 初稿(未考虑checkboxlist等控件) //
if (cThis == null)
return;
var tagName = cThis.tagName;
if (tagName != null) {
tagName = tagName.toLowerCase();
}
// 考虑div/span的情况 //
switch (tagName) {
case "span":
case "table":
case "label":
case "div":
case "tbody":
case "tr":
case "td":
case "th":
cThis.innerHTML = theValue;
return;
default:
break;
}
if(tagName == "input") {
// 考虑checkbox的情况 //
var typeName = cThis.type;
if (typeName != null) {
typeName = typeName.toLowerCase();
}
if (typeName == "checkbox") {
if (theValue == "1" || (theValue + "").toLowerCase() == "true") {
cThis.checked = true;
}
else {
cThis.checked = false;
}
return;
}
}
cThis.value = theValue;
}
上一条:
下一条:
相关评论
发表评论