[英]Jquery is selecting only the first option from select dropdown
<script type="text/javascript">
$(function () {
$("[id*=btnSave]").bind("click", function () {
debugger;
var user = {};
user.Projectname = $('#select-comm-type').find("option:selected").text();
user.Emailid = $("[id*=Emailtext]").val();
$.ajax({
type: "POST",
url: "FrmTmsClient.aspx/SaveEmail",
data: '{user: ' + JSON.stringify(user) + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert("EmailId has been added successfully.");
window.location.reload();
}
});
return false;
});
});
</script>
在user.Projectname中,僅使用id = select-comm-type的select中的第一個選項。 我要選擇其他選項。
對於選定的值
jQuery("#select-comm-type option:selected").val();
要么
$("#select-comm-type option:selected").val();
和
對於的選定文本
jQuery("#select-comm-type option:selected").text();
要么
$("#select-comm-type option:selected").text();
更多細節:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.