js为select赋值,省市县三级联动,如何获取这三个的value

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

<form aciton="../php/register.php" method="post">
<p>
<label style="color: #ffffff;width: 40%;text-align: right;">所  在  省:</label>
<select style="width:75%;" id="s_province" name="s_province" onchange="setVal1(this.options[this.selectedIndex].text)"></select>
</p>
<p>
<label style="color: #ffffff;width: 40%;text-align: right;">所  在  市:</label>
<select style="width:75%;" id="s_city" name="s_city" onchange="setVal2(this.options[this.selectedIndex].text)"></select>
</p>
<p>
<label style="color: #ffffff;width: 40%;text-align: right;">所  在  县:</label>
<select style="width:75%;" id="s_county" name="s_county" onchange="setVal3(this.options[this.selectedIndex].text)"></select>
</p>
<input type="hidden" id="shengText" value="" name="shengText"/>
<input type="hidden" id="xianText" value="" name="xianText"/>
<input type="hidden" id="shiText" value="" name="shiText"/>
<script class="resources library" src="http://sandbox.runjs.cn/uploads/rs/267/g3ugugjp/area.js" type="text/javascript"></script>
<script type="text/javascript">_init_area();</script>
<p><button type="submit" class="button1">注 册</button>
</p>
</form>
</div>
</body>
<script type="text/javascript">
var Gid = document.getElementById ;
var showArea = function(){
Gid('show').innerHTML = "<h3>省" + Gid('s_province').value + " - 市" +
Gid('s_city').value + " - 县/区" +
Gid('s_county').value + "</h3>"
}
Gid('s_county').setAttribute('onchange','showArea()');
</script>
<script language="javascript">
function setVal1(_text)
{
document.getElementById("shengText").value=_text;
}
function setVal2(_text)
{
document.getElementById("shiText").value=_text;
}
function setVal3(_text)
{
document.getElementById("xianText").value=_text;
}
</script>


这样我是能获取到值, 但是只获取到最后一个 县的那个 select值。 试了半个小时。发现是js文件为select赋值的原因。 有没有什么其他办法。 既可以用js文件为select赋值,还能获取到值为文本框赋值。
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
dahuzigkl
JavaScript 87,984 成员 224,681 内容