[英]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.