gpt4 book ai didi

jquery - 将值传递给 jquery 对话框表单

转载 作者:行者123 更新时间:2023-12-01 02:00:48 25 4
gpt4 key购买 nike

我需要一个对话框窗口来弹出一个表单并将值传递给该表单。我尝试了多种方法来解决这个问题,但一直未能成功。我到处寻找,似乎没有任何效果。

这是我最近的尝试:

  var message="variable";

.click(function() {
$( "#dialog-form" ).dialog( "open" );
$('<input>').attr({
type: 'text',
id: 'hidden-input",
value: message,
name: 'bar'
}).appendTo("#dialog-form");

如果我将附加内容放入对话框中,弹出窗口将停止工作(我想我不知道如何正确执行此操作)

最佳答案

我完全使用脚本来处理对话框(我认为它更干净):

http://jsfiddle.net/fE6q2/

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();
}

关于jquery - 将值传递给 jquery 对话框表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15317953/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com