[英]Jquery set value of option element to be the text of the element
我需要將option元素的value屬性設置為等於option元素本身的文本。 這是我目前的代碼。 由於某種原因,它連接字符串。
這是HTML標記。
<select id="ResidentialBuildingType" name="ResidentialBuildingType">
<option>SFD</option>
<option>Test</option>
</select>
這是jquery代碼:
<script>
$(document).ready(function () {
var select = $('#ResidentialBuildingType > option');
$(select).each(function (index) {
console.log(select.text());
});
});
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.