Last active
December 15, 2015 08:59
-
-
Save ethanfu/5234579 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//回写表单 | |
//可以处理select,但是不允许select的option的value出现","字符 | |
function writeBackValue(inputName) { | |
if (form.elements[inputName] == undefined) { | |
return false; | |
} | |
if (form.elements[inputName].value != undefined) { //如果有value属性,直接赋值 | |
form.elements[inputName].value = mForm[inputName]; | |
jQuery("#" + inputName).val(mForm[inputName]); | |
} | |
if (form.elements[inputName].length != undefined) { //没有value属性 | |
var thisValue = mForm[inputName]; | |
if (mForm[inputName] == undefined && mForm[inputName][0] == undefined) { | |
thisValue = new Array(); | |
thisValue[thisValue.length] = mForm[inputName]; | |
} | |
if (form.elements[inputName].length != null) { //length不为空 | |
var tempLength = form.elements[inputName].length; | |
for (var j = 0; j < tempLength; j++) { | |
var thisObj = form.elements[inputName][j]; | |
var valueSplit = thisValue.split(","); | |
for (var k = 0; k < valueSplit.length; k++) { | |
if (thisObj.value == valueSplit[k]) { //如有选中,继续循环 | |
if (thisObj.checked != undefined) { | |
thisObj.checked = true; | |
break; | |
} else if (thisObj.selected != undefined) { | |
thisObj.selected = true; | |
break; | |
} | |
} else { //如没有选中,察看下一个 | |
if (thisObj.checked != undefined) { | |
thisObj.checked = false; | |
} else if (thisObj.selected != undefined) { | |
thisObj.selected = false; | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment