gpt4 book ai didi

Javascript:从按钮调用对话框

转载 作者:行者123 更新时间:2023-12-03 09:49:19 24 4
gpt4 key购买 nike

我希望你能帮助我,因为我是 javascript 新手。我想通过单击按钮打开一个对话框。当它出现并单击“确定”时,应该会弹出第二个对话框。

http://forums.asp.net/t/1962249.aspx?Make+a+button+open+a+javascript+dialog

还在 stackoverflow 上我看到了相关问题。但他们都无法回答我的问题:我做错了什么或者我应该做什么才能让它发挥作用?

我的代码是:

    <!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Dialog - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$( "#dialog" ).dialog(
{
autoOpen:false,
maxHeight: 250,
maxWidth: 600,
buttons: [
{
text: "Ok",
icons: { primary: "ui-icon-check"},
click: function()
{
$( this ).dialog( "close" );
$("#dialog2").dialog("open");
}
},

{
text: "Cancel",
icons: { primary: "ui-icon-close"},
click: function() {
$( this ).dialog( "close" );
}
}
]
});
$( "#dialog2" ).dialog(
{
autoOpen: false,
maxHeight: 400,
maxWidth: 600,
buttons: [
{
text: "Ok",
icons: { primary: "ui-icon-check"},
click: function()
{
$( this ).dialog( "close" );
$("#dialog3").dialog("open");
}
},

{
text: "Cancel",
icons: { primary: "ui-icon-close"},
click: function() {
$( this ).dialog( "close" );
}
}
]
});
$( "#dialog3" ).dialog(
{
autoOpen: false,
maxHeight: 400,
maxWidth: 600,
buttons: [
{
text: "Ok",
icons: { primary: "ui-icon-check"},
click: function()
{
$( this ).dialog( "close" );
$("#dialog3").dialog("open");
}
},

{
text: "Cancel",
icons: { primary: "ui-icon-close"},
click: function() {
$( this ).dialog( "close" );
}
}
]
});
});
$function myFunction(){
$( "#btn1" ).click(function() {
$("#dialog").dialog("open");
}
}
</script>
</head>
<body>

<div id="dialog" title="Basic dialog">
<p>Tekst</p>
</div>

<div id="dialog2" title="Basic dialog">
<p>Tekst</p>
</div>

<div id="dialog3" title="Basic dialog">
<p>Test.</p>
</div>

<button id="btn1" onclick="myFunction()" class="ui-state-default ui-corner-all">Click Here</button>

</body>
</html>

最佳答案

只需将 click 处理程序注册如下:

$( "#btn1" ).click(function() {
$("#dialog").dialog("open");
});

在您已经创建对话框的 domReady 函数内。

并删除这部分:

$function myFunction(){
$( "#btn1" ).click(function() {
$("#dialog").dialog("open");
}
}

并在 input 元素中删除 onclick 属性。

<button id="btn1" class="ui-state-default ui-corner-all">Click Here</button>

您必须对每个按钮/对话框组合执行相同的操作。

参见demo

关于Javascript:从按钮调用对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30925385/

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