繁体   English   中英

jQuery从选择下拉列表中仅选择第一个选项

[英]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();

更多细节:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM