简体   繁体   English

单击按钮时将现有页面/表单作为模式加载

[英]Load an existing page/form as a modal on button click

I have an existing webpage that contains a form for submitting questions. 我有一个现有的网页,其中包含用于提交问题的表格。

Existing Form Page 现有表单页面

I want to load that form as a modal/pop-up on my homepage when someone clicks a button. 当有人单击按钮时,我想在主页上将该表格作为模式/弹出窗口加载。

I don't want the user to have to navigate away from the page they are on. 我不希望用户必须离开他们所在的页面。 They should be able to fill out the form and submit after clicking the button. 他们应该能够填写表格并在单击按钮后提交。

I thought I could use jQuery .load() but I think I am using it incorrectly. 我以为可以使用jQuery .load()但我认为使用不正确。

I have placed the html/JQuery in the file containing my homepage. 我已将html / JQuery放置在包含主页的文件中。

I am not sure what to put as an argument in .load() , the page url or the file? 我不确定在.load() ,页面url或文件中将什么作为参数? I have tried both and neither work. 我已经尝试过,但都没有工作。

Homepage 主页

<div id="PopUpForm">Pop Up Form</div>
<a href="#" onclick="openDialog();">Button</a>

 <script type="text/javascript">
function openDialog() {
   $("#PopUpForm").load('question-submit-form.php').dialog({modal: true});
} 
</script>

You have to make sure that the 'question-submit-form.php' is in the right directory. 您必须确保“ question-submit-form.php”在正确的目录中。 Also make sure to include jqueryUI script and css. 还请确保包括jqueryUI脚本和CSS。 The following works fine for me. 以下对我来说很好用。

<!--jqueryUI css -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css">

<!-- body -->

<div id="PopUpForm">Pop Up Form</div>
<a href="#" onclick="openDialog();">Button</a>


<!-- include jquery and jquery ui and jqueryUI js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>

<script type="text/javascript">
   function openDialog() {
     $("#PopUpForm").load('question-submit-form.php').dialog({model:true});
   } 
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM