Struts1通过ID/styleId获取下拉框绑定的值
前言
Struts1想获取下拉组建的值 通过ID的方式,直接使用H5不太行
<html:select name="tripFeeConfigureForm" property="vo.checkType" styleId="checkType2" style="width: 150px;">
<html:option value="">请选择</html:option>
<html:option value="0">弱校验</html:option>
<html:option value="1">强校验</html:option>
</html:select>
<!-- 可获取到整个select Dom元素-->
console.log(document.getElementById("checkType2"));
<!-- 以下方法获取不到-->
console.log($("#checkType2 option:selected"));
console.log($("#checkType2 option:selected").val());
var options=$("#checkType2 option:selected").val());
console.log(document.getElementById("checkType2").options[selected].value);
var checkType =document.getElementById("checkType2").options[select.selectedIndex].value;
解决
跳出固有获取方式,使用JQueryID选择器 即可解决,styleId相当于ID,直接使用即可
jQuery #id 选择器
console.log($("#checkType2 option:selected"));
console.log($("#checkType2 option:selected").val());
使用自带的可通过name获取
console.log(document.getElementsByName("vo.checkType")[0].value);

浙公网安备 33010602011771号