【问题标题】:I want to create auto pop up with contact form in php script我想在 php 脚本中创建带有联系表单的自动弹出窗口
【发布时间】:2015-12-03 02:29:09
【问题描述】:

我想创建一个自动弹出联系表。当用户访问我的网站时...自动显示弹出表单。

我正在尝试一些代码,但在单击按钮后它会弹出表单(效果很好)。现在我正在尝试创建不需要任何按钮的自动弹出窗口...

我的 html 文件在这里

<html>
 <head>
 <title>Popup contact form</title>
<link href="elements.css" rel="stylesheet">
<script src="my_js.js"></script>
</head>
<!-- Body Starts Here -->
<body id="body" style="overflow:hidden;">
<div id="abc">
<!-- Popup Div Starts Here -->
<div id="popupContact">
<!-- Contact Us Form -->
<form action="#" id="form" method="post" name="form">
<img id="close" src="images/3.png" onclick ="div_hide()">
<h2>Contact Us</h2>
   <hr>
<input id="name" name="name" placeholder="Name" type="text">
<input id="email" name="email" placeholder="Email" type="text">
<textarea id="msg" name="message" placeholder="Message"></textarea>
<a href="javascript:%20check_empty()" id="submit">Send</a>
</form>
</div>
<!-- Popup Div Ends Here -->
</div>
<!-- Display Popup Button -->
<h1>Click Button To Popup Form Using Javascript</h1>
<button id="popup" onclick="div_show()">Popup</button>
</body>
<!-- Body Ends Here -->
</html>

我的 java 脚本文件是这样的

// Validating Empty Field
function check_empty() {
if (document.getElementById('name').value == "" ||        document.getElementById('email').value == "" ||     document.getElementById('msg').value == "") {
alert("Fill All Fields !");
} else {
document.getElementById('form').submit();
alert("Form Submitted Successfully...");
}
}
//Function To Display Popup
function div_show() {
document.getElementById('abc').style.display = "block";
}
//Function to Hide Popup
function div_hide(){
document.getElementById('abc').style.display = "none";
} 

我有一些 CSS 代码。这里就不提了。

如何创建不需要任何按钮的自动弹出表单?

【问题讨论】:

    标签: javascript php html forms contact


    【解决方案1】:

    您需要在页面 (DOM) 加载后调用“弹出方法”:

    http://www.w3schools.com/jsref/dom_obj_document.asp

    jQuery:

    $(document).ready(function(){
      div_show();
    }
    

    原生 JS:

    document.addEventListener("DOMContentLoaded", function(event) { 
      div_show();
    });
    

    您可能感兴趣的其他链接:

    $(document).ready equivalent without jQuery

    http://www.w3schools.com/bootstrap/bootstrap_ref_js_modal.asp

    https://jqueryui.com/dialog/

    问候

    【讨论】:

    • 将此代码添加到 js 文件时运行良好 //函数在页面加载 10 秒后调用 div_show() 函数 setTimeout(function() { div_show(); }, 10000);跨度>
    • 所以如果对您有帮助,请为答案投票并将其标记为已解决
    猜你喜欢
    • 2021-10-31
    • 1970-01-01
    • 1970-01-01
    • 2018-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    相关资源
    最近更新 更多