现在有一个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基本不懂操作 寻求热心人解答 帮忙 谢谢了
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基本不懂操作 寻求热心人解答 帮忙 谢谢了
document.getElementById("Spr").value=this.options[this.selectedIndex].getAttribute("Sprice");
<option value='' Sprice='66'>77 </option> value里是有值的 只是在这里粘贴我没写上我直接用你这个替换掉原来的 还是一样的啊如何把这个值传过去的ne
<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>
我就是找的这个
document.getElementById("Spr").value=this.options[this.selectedIndex].Sprice;
但现在是 我点选这个操作的时候 有2个动作要触发首先它是联动 之后还要把这个Sprice的值传过去我就是不知道把这个
document.getElementById("Spr").value=t.options[t.selectedIndex].getAttribute("Sprice");
加在哪里
onchange='javascript:if(this.value!="") setCzys(this.options[this.selectedIndex].value);document.getElementById("Spr").value=this.options[this.selectedIndex].Sprice;'>
有2个动作
首先是联动
其次是这个select还有一个值要传给input 显示出来
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"/>
这个就是测试代码了
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++;
}
}