select关联input数据方法,并且用_分割数据实现过个input
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>
<script>
window.onload=selectShow;
function selectShow(){
var selectobj = document.getElementById("slList");
var index = selectobj.selectedIndex;
var option_val = selectobj.options.value;
var person_arr = option_val.split("_");
varperson_name = person_arr,
person_gender = person_arr,
person_identity = person_arr;
document.getElementById("txtShow").value = person_name;
document.getElementById("txtShow1").value = person_gender;
document.getElementById("txtShow2").value = person_identity;
}
</script>
页:
[1]