0

新手 jquery 用户在这里。我希望在输入被聚焦/选择时打开一个模态,并从模态中的按钮向输入输入一个值。

所以事件将是。1. 聚焦输入。2. 打开一个模态。3. 通过使用按钮将值输入到输入中。4. 关闭按钮时关闭模态框。

非常感谢。

4

2 回答 2

2

你会想要prompt()

$('body').on('focus', 'input[name=myNameHere]', function(){
    var input = prompt('The Question', 'Suggested answer');
    $(this).val(input);
});

或者通过jQuery UI的更高级的对话框。

于 2013-01-08T09:46:25.620 回答
0

这可能是您正在寻找的:

<!doctype html>

<html lang="en">
<head>
    <meta charset="utf-8" />    
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.8.3.js"></script>    
    <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>    
    <script>
    $(function() {
        $( "#dialog" ).dialog({modal: true, autoOpen:false});

        $("#result").focus(function () {
            $( "#dialog" ).dialog("open");
        });

        $('#accept').click(function (){
            $('#result').val($('#source').val());
            $('#dialog').dialog("close");
        });

    });
    </script>
</head>
<body>

 <input type="text" id="result"> 
 </div>

<div id="dialog" title="Basic dialog">
    Enter value <input type="text" id="source" /><br/>
    <input type="button" id="accept" value="OK" />
</div>

</body>
</html>
于 2013-01-08T09:57:24.380 回答