一个js二级联动 在回显值的问题

沧海小鱼 沧海小鱼 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
现在有一个js二级联动

代码是这样的

<script type='text/javascript'>
function removeOptions(selectObj){
if(typeof selectObj != 'object'){
selectObj = document.getElementById(selectObj);
}
var len = selectObj.options.length;
for(var i=0 ; i<len ;i++){
selectObj.options[0] = null;
}
}
function setSelectOption(selectObj, optionList, firstOption, selected){
if(typeof selectObj != 'object'){
selectObj = document.getElementById(selectObj);
}
removeOptions(selectObj);
var start = 0;
if(firstOption){
selectObj.options[0] = new Option(firstOption,'');
start ++;
}
var len = optionList.length;
for(var i=0; i<len; i++){
selectObj.options[start] = new Option(optionList[i].txt,optionList[i].val);
if(selected == optionList[i].val){
selectObj.options[start].selected = true;
}
start++;
}
}
</script>
<script type='text/javascript'>
----------
数据动态调取 省略
------------
function setCzys(CzSel){
setSelectOption('Czys',cityArr[CzSel],'-请选择-');
}
</script>



我现在想要的效果是 我点击第一个下拉单的时候 希望能把值在回显到另外一个input框(Spr) 以作为表单里的一项数据提交

<select id='CzSel' name='CzSel' onchange='if(this.value!="") setCzys(this.options[this.selectedIndex].value);document.getElementById("Spr").value=this.options[this.selectedIndex].Sprice;'>
<option value='' Sprice='22'>-请选择-</option>
<option value='' Sprice='66'>77</option>
</select>
颜色:<select id='Czys' name='Czys'>
<option value=''>-请选择-</option>
</select>
<input name="Spr" type="text" id="Spr" size="10"/>

这一句是我自己加的
document.getElementById("Spr").value=this.options[this.selectedIndex].Sprice;

对js基本不懂操作 寻求热心人解答 帮忙 谢谢了
...全文
评论 13
收藏 已收藏
分享
返回顶部
沧海小鱼
JavaScript 87,984 成员 224,681 内容