现在有一个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基本不懂操作 寻求热心人解答 帮忙 谢谢了 

解决方案 »

  1.   

    你的select的option中value没有给值,自定义了一个Sprice属性,你得去获取这个属性。如下
    document.getElementById("Spr").value=this.options[this.selectedIndex].getAttribute("Sprice"); 
      

  2.   

    <option value='' Sprice='22'>-请选择- </option> 
    <option value='' Sprice='66'>77 </option> value里是有值的 只是在这里粘贴我没写上我直接用你这个替换掉原来的 还是一样的啊如何把这个值传过去的ne
      

  3.   

    如下代码是没问题的,你传不过去值,可能是你其他地方的代码影响了!检查一下<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
     </HEAD> <BODY>
     <select id="s1" onchange="setSlValue(this)"> 
      <option value='' Sprice='22'>-请选择- </option> 
    <option value='' Sprice='66'>77 </option> 
    </select> 
    <input name="Spr" type="text" id="Spr"  size="10"/> 
     </BODY>
    </HTML><SCRIPT LANGUAGE="JavaScript">
    <!--
    function setSlValue(t)
    {
    document.getElementById("Spr").value=t.options[t.selectedIndex].getAttribute("Sprice"); 
    }
    //-->
    </SCRIPT>
      

  4.   

    这个是可以传值的 
    我就是找的这个
    document.getElementById("Spr").value=this.options[this.selectedIndex].Sprice;
    但现在是 我点选这个操作的时候 有2个动作要触发首先它是联动 之后还要把这个Sprice的值传过去我就是不知道把这个
    document.getElementById("Spr").value=t.options[t.selectedIndex].getAttribute("Sprice"); 
    加在哪里
      

  5.   

    改为:
    onchange='javascript:if(this.value!="") setCzys(this.options[this.selectedIndex].value);document.getElementById("Spr").value=this.options[this.selectedIndex].Sprice;'>
      

  6.   

    一个select的联动 我点击选项的时候 
    有2个动作 
    首先是联动
    其次是这个select还有一个值要传给input  显示出来
      

  7.   

    这两个动作不冲突的,select的onchange事件中,先去控制联动,然后将当前的select的值赋给一个input显示。你老说不能显示,肯定是你代码有些地方有问题,得逐条去分析!把你整个代码贴出来!
      

  8.   

    <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'>
    var cityArr = [];cityArr['pu皮质'] = [ {txt:'白色242',val:'3'},
     
    {txt:'白色3',val:'4'},
     
    ];
     
    cityArr['giuu'] = [ {txt:'白色',val:'5'},
     
    {txt:'黑色',val:'6'},
     
    ];
     
    function setCzys(CzSel){
    setSelectOption('Czys',cityArr[CzSel],'-请选择-');
    }</script><select id='CzSel' name='CzSel' onchange='javascript:if(this.value!="") setCzys(this.options[this.selectedIndex].value);document.getElementById("Spr").value=this.options[this.selectedIndex].Sprice;'>
    <option value='0' Sprice='22'>-请选择-</option>

    <option value='pu皮质' Sprice='pu皮质'>pu皮质</option>
     
    <option value='giuu' Sprice='giuu'>giuu</option>
     
    </select>
    颜色:<select id='Czys' name='Czys'>
    <option value=''>-请选择-</option>
    </select>
    <input name="Spr" type="text" id="Spr"  size="10"/>
    这个就是测试代码了
      

  9.   


    var len = optionList.length;
        for(var i=0; i<len; i++){
    if(optionList[i]){
            selectObj.options[start] = new Option(optionList[i].txt,optionList[i].val);
            if(selected == optionList[i].val){
                selectObj.options[start].selected = true;
            }
            start++;
    }
        }