通过document.getElementByTagName[select][1].value;
我可以获取我的价值,如果我想使用div
获取价值,例如select
div
框值
<select>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<div id="firstdiv">
<select>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<select>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
</div>
答案 0 :(得分:0)
像这样......
//get the div
var theDiv = document.getElementById("firstdiv");
//get the first select option from thediv
var theSelect = theDiv.getElementsByTagName("select")[0].value;
console.log("theVal",theSelect)
由于您还将此标记为jQuery问题,因此添加此
var theSelect = $("#firstdiv select :first").val();
console.log("theVal",theSelect)