Javascript 如何在对话框中加载html页面并作为弹出窗口打开
我有这个单独的html页面,我想打开作为一个按钮点击对话,这是可能的吗?我们怎样才能做到这一点Javascript 如何在对话框中加载html页面并作为弹出窗口打开,javascript,jquery,html,Javascript,Jquery,Html,我有这个单独的html页面,我想打开作为一个按钮点击对话,这是可能的吗?我们怎样才能做到这一点 <div id="dialog-form" title="Change Password"> <form> <div class="border"> <label for="oldPassword">Old Password</label> <input type="
<div id="dialog-form" title="Change Password">
<form>
<div class="border">
<label for="oldPassword">Old Password</label>
<input type="password" id ="oldPassword" placeholder="Enter Old Password">
<label for="newPassword">New Password</label>
<input type="password" id="newPassword" placeholder="Enter New Password">
<label for="retypePassword">Retype Password</label>
<input type="password" id="retypePassword" placeholder="Enter Retype password">
</div>
<div class="buttons">
<button id="submit">Submit</button>
<button id="cancel">Cancel</button>
</div>
</form>
</div>
旧密码
新密码
重新输入密码
提交
取消
是的,请查看下面的链接以实现此目的,它非常简单:
因为您不想使用jquery手机弹出窗口
这样做:
$('#dialog-form').click(function(){
window.open('url', 'window name', 'window settings');
return false;
});
在url上,粘贴html文件的链接,此外,您还可以命名窗口并添加其他设置,如高度、宽度等,如果您对答案满意,您可以投赞成票。谢谢:)因此,我建议使用类似JQuery UI的样式框架 它非常简单且易于设置: 对于您的示例,您可以使用:
<head>
<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-form" ).dialog();
});
</script>
</head>
<div id="dialog-form" title="Change Password">
<form>
<div class="border">
<label for="oldPassword">Old Password</label>
<input type="password" id ="oldPassword" placeholder="Enter Old Password">
<label for="newPassword">New Password</label>
<input type="password" id="newPassword" placeholder="Enter New Password">
<label for="retypePassword">Retype Password</label>
<input type="password" id="retypePassword" placeholder="Enter Retype password">
</div>
<div class="buttons">
<button id="submit">Submit</button>
<button id="cancel">Cancel</button>
</div>
</form>
</div>
您想创建一个对话框,并通过单击不同的按钮添加不同的HTML代码吗 1.创建一个div,使其看起来像一个对话框。不要展示它
<div id="dialog-form" title="Change Password" style="display: none;"> </div>
2.如下定义变量:
var html = '<form>' +
'<div class="border">' +
'<label for="oldPassword">Old Password</label>' +
'<input type="password" id ="oldPassword" placeholder="Enter Old Password">' +
'<label for="newPassword">New Password</label>' +
'<input type="password" id="newPassword" placeholder="Enter New Password">' +
'<label for="retypePassword">Retype Password</label>' +
'<input type="password" id="retypePassword" placeholder="Enter Retype password">' +
'</div>' +
'<div class="buttons">' +
'<button id="submit">Submit</button>' +
'<button id="cancel">Cancel</button>' +
'</div>' +
'</form>';
var html=''+
'' +
“旧密码”+
'' +
“新密码”+
'' +
“重新键入密码”+
'' +
'' +
'' +
“提交”+
“取消”+
'' +
'';
3.添加$('#对话框表单').html(html).css('display','block')代码>在单击处理程序中
您还可以通过$('#dialog form').html(''.css('display','none'))隐藏对话框代码>您可以使用引导轻松地在单击按钮时打开一个对话框
如果您在项目中使用模板,并且希望在单击按钮时打开一个对话框,那么有时候jquery对话框并没有提供我的经验中的正确输出,所以我使用bootstrap
dialog(model)
小模态
修改密码
旧密码
新密码
重新输入密码
提交
取消
我试过点击$('')按钮。加载(页面名称);但这不起作用我是jquery新手,Javascript谢谢:)但我不想让jquery手机弹出。事实上,我想以dailog-in相对窗口的形式打开这个给定的html页面。如果页面是单独的,也许可以在你的帖子中添加一个ajax调用examle,因此,可以从其他操作/页面加载页面。感谢回复:)。这看起来很棒,但这是在同一页面中显示表单,而不是打开日志
var html = '<form>' +
'<div class="border">' +
'<label for="oldPassword">Old Password</label>' +
'<input type="password" id ="oldPassword" placeholder="Enter Old Password">' +
'<label for="newPassword">New Password</label>' +
'<input type="password" id="newPassword" placeholder="Enter New Password">' +
'<label for="retypePassword">Retype Password</label>' +
'<input type="password" id="retypePassword" placeholder="Enter Retype password">' +
'</div>' +
'<div class="buttons">' +
'<button id="submit">Submit</button>' +
'<button id="cancel">Cancel</button>' +
'</div>' +
'</form>';
<div class="container">
<h2>Small Modal</h2>
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#dialog-form">Change Password</button>
<div id="dialog-form" title="Change Password" class="modal fade" role="dialog">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<form>
<div class="border">
<label for="oldPassword">Old Password</label>
<input type="password" id ="oldPassword" placeholder="Enter Old Password">
<label for="newPassword">New Password</label>
<input type="password" id="newPassword" placeholder="Enter New Password">
<label for="retypePassword">Retype Password</label>
<input type="password" id="retypePassword" placeholder="Enter Retype password">
</div>
<div class="buttons">
<button id="submit">Submit</button>
<button id="cancel">Cancel</button>
</div>
</form>
</div>
</div>
</div>
</div>