如何在jQuery弹出窗口中显示下拉列表选择列表并检索所选值

时间:2012-05-04 12:28:01

标签: javascript jquery html jquery-ui

我想在jQuery Popup / Dialog中显示一个select-dropdown列表。你能否告诉我如何做到这一点,以及如何检索所选的值?

以下示例代码:

<div id='selectPopup'>
    <form name='test'>
        <select  id='inptPAN' name='inptPAN'>
            <option value='1'>item 1</option>
            <option value='2'>item 2</option>
            <option value='3'>item 3</option>
            <option value='4'>item 4</option>
            <option value='5'>item 5</option>
            <option value='6'>item 6</option>
        </select>
    </form>
</div>

请参阅此jsFiddle了解一些代码

1 个答案:

答案 0 :(得分:0)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="../../../Scripts/css/ui-lightness/jquery-ui-1.8.16.custom.css" rel="stylesheet"
        type="text/css" />
    <script src="../../../Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script src="../../../Scripts/jquery-ui-1.8.16.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            // this function is triggered as soon as something changes in the form
            $("select[name='inptPAN']").change(function () {
                //console.log('found change');
              selectDialog('Pan','You had selected, Text: '+ $(':selected',this).text()+' And Value : '+$(this).val());
            });

            function selectDialog(title, text) {
                return $('<div></div>').append(text)
            .dialog({
                resizable: true,
                modal: true,
                buttons: {
                    "OK": function () {
                        $(this).dialog("close");
                    }
                }
            });
            }
        });
    </script>
</head>
<body>
    <div id='selectPopup'>
        <form name='test'>
        <select id='inptPAN' name='inptPAN'>
            <option value='1'>item 1</option>
            <option value='2'>item 2</option>
            <option value='3'>item 3</option>
            <option value='4'>item 4</option>
            <option value='5'>item 5</option>
            <option value='6'>item 6</option>
        </select>
        </form>
    </div>
</body>
</html>

Demo