2

我想在 jQuery 弹出/对话框中显示一个选择下拉列表。你能告诉我如何做到这一点,以及如何检索选定的值吗?

下面的示例代码:

<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获取一些代码

4

1 回答 1

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>

演示_

于 2012-05-04T12:48:12.787 回答