我需要一个弹出窗体的对话窗口,并将值传递给此窗体。我尝试了几种解决这个问题的方法,但我无法这样做。我一直在搜索,似乎什么都没有用。
这是我最近的尝试:
var message="variable";
.click(function() {
$( "#dialog-form" ).dialog( "open" );
$('<input>').attr({
type: 'text',
id: 'hidden-input",
value: message,
name: 'bar'
}).appendTo("#dialog-form");
如果我把追加放在对话框中弹出停止工作(我想我不知道如何正确地做到这一点)
答案 0 :(得分:6)
我完全使用脚本进行对话处理(我认为它更干净):
HTML:
Default firstname:<br>
<input type='text' id="default_firstname"/>
<br><br>
<button onclick='on_create_form_clicked()'>create form</button>
的javascript:
function on_create_form_clicked()
{
var html =
"<div>" +
"Firstname:<br>" +
"<input type='text' class='firstname'/>" +
"<br/><br/>" +
"Lastname:<br>" +
"<input type='text' class='lastname'/>" +
"<br/><br/>" +
"<button class='ok'>ok</button>" +
"</div>";
var div = $(html);
var default_firstname = $('#default_firstname').val();
div.find('.firstname').val(default_firstname);
div.find('.ok').click(function()
{
div.dialog('close');
var firstname = div.find('.firstname').val();
var lastname = div.find('.lastname').val();
alert("firstname was " + firstname
+ " and lastname was " + lastname);
});
div.dialog(
{
title:"Enter firstname and lastname",
close: destroy_this_dialog
});
}
function destroy_this_dialog(event, ui)
{
$(this).dialog("destroy");
$(this).remove();
}
答案 1 :(得分:5)
我想你正在寻找这样的东西:
<script>
$(function(){
var message = "variable";
$("#showDialog").click(function() {
$("#hidden-input").val(message);
$("#dialogForm").dialog("open");
});
});
</script>
<button id="showDialog">Show Dialog</button>
<div id="dialogForm">
<input type="text" id="hidden-input" name="bar"/>
</div>