select关联input数据方法,并且用_分割数据实现过个input数据自动填写:
姓名<input type="text" id="txtShow"/>请选择
<select id="slList">
<option value="张三_男_警察">张三</option>
<option value="李四_女_农民">李四</option>
<option value="王五_男_土匪">王五</option>
<option value="六六_未知_不清楚">六六</option>
</select><BR>
性别<input type="text" id="txtShow1"/><BR>
身份<input type="text" id="txtShow2"/><BR>
[JavaScript] 纯文本查看 复制代码 <script>
window.onload=selectShow;
function selectShow(){
var selectobj = document.getElementById("slList");
var index = selectobj.selectedIndex;
var option_val = selectobj.options[index].value;
var person_arr = option_val.split("_");
var person_name = person_arr[0],
person_gender = person_arr[1],
person_identity = person_arr[2];
document.getElementById("txtShow").value = person_name;
document.getElementById("txtShow1").value = person_gender;
document.getElementById("txtShow2").value = person_identity;
}
</script> |