jsp select 选中获取选中对象的值

问题说明:

需要选中服务人群select后,带入相应的信息.

如何解决?

jsp页面

<select class="js-example-basic-single" name="servicePackageId" id="servicePackageId"  style="width: 300px;" οnchange="selectCrowd()"  >
    <option value=""></option>
    <c:forEach items="${checkPackageDatas}" var="item">
        <option value="${item.id}" content="${item.content}">${item.targetCrowd}</option>
    </c:forEach>
</select>
js:
function selectCrowd(){
    var myselect = document.getElementById("servicePackageId");
    var index=myselect.selectedIndex ;
    $("#content").val(myselect.options[index].getAttribute('content'));
}

猜你喜欢

转载自blog.csdn.net/KeepLearnZhangXiaoBo/article/details/114732751