Jquery只从select下拉列表中选择第一个选项

时间:2017-07-11 06:53:33

标签: javascript jquery asp.net ajax

<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中的

仅从select = select-comm-type中选择第一个选项。我想要选择其他选项。

1 个答案:

答案 0 :(得分:0)

对于

的选定
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();

更多详情:

http://api.jquery.com/val/

http://api.jquery.com/text/