javascript PHP代码执行后关闭窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22347983/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 22:58:13  来源:igfitidea点击:

Close window after PHP code is executed

javascriptphp

提问by user3403327

Hey Guys so I have two problems

嘿伙计们所以我有两个问题

  1. How do I close the window once I Have executed my PHP code which is a simple save textbox values to database?

  2. How do I get my text boxes to align so they perfectly aligned currently one is more indented than the other DEMO?

  1. 一旦我执行了我的 PHP 代码(将文本框值简单地保存到数据库),我该如何关闭窗口?

  2. 如何让我的文本框对齐,以便它们完美对齐,目前一个比另一个更缩进DEMO

Here's the PHP code that saves data into my database once saved I want the current window to close:

这是在保存后将数据保存到我的数据库中的 PHP 代码我希望当前窗口关闭:

<form name="Permit" id="Permit" action="<?php echo JURI::current(); ?>" method="post">
    Permit or Deny: <input align= center  type="text" name="Permit_or_Deny" value=""><br>
    Level <input type="text" name="Level" value=""><br>
    <p><input id="submit" name="submit" type="submit" value="Permit Or Deny Submit Buutton" /></p>
</form>


<?
if ((isset($_POST['Permit_or_Deny'])) || (isset($_POST['Level']))) {
    //first name or last name set, continue-->
    $Permit_or_Deny = $_POST['Permit_or_Deny'];
    $Level          = $_POST['Level'];

    $db =& JFactory::getDBO();
    $query = "INSERT INTO tp_newedit (Permit_or_Deny, Level) VALUES ('" . $Permit_or_Deny . "','" . $Level . "');";

    $db->setQuery($query);
    $db->query();
} else {
    echo '<h4>One Field Is Required!</h4>';
}
?>

回答by halkujabra

For first part -

第一部分——

<form name="Permit" id="Permit" action="<?php echo JURI::current(); ?>" method="post">

    <div class="label" style="display:inline-block;width:200px"> Permit or Deny: </div><input align= center  type="text" name="Permit_or_Deny" value=""/><br>
        <div class="label" style="width:200px;display:inline-block;"> Level </div> <input type="text" name="Level" value=""><br>

        <p><input id="submit" name="submit" type="submit" value="Permit Or Deny Submit Buutton" /></p>
    </form>

For second part, place this on server side code-

对于第二部分,将其放在服务器端代码上-

<?php    
    /* ... SQL EXECUTION TO UPDATE DB ... */

    echo "<script>window.close();</script>";
?>

回答by Ashoka Mondal

Try window.close()of JavaScript:-

尝试window.close()JavaScript:-

<?

if ((isset($_POST['Permit_or_Deny'])) || (isset($_POST['Level']))) {
    //first name or last name set, continue-->
    $Permit_or_Deny = $_POST['Permit_or_Deny'];
    $Level          = $_POST['Level'];

    $db =& JFactory::getDBO();
    $query = "INSERT INTO tp_newedit (Permit_or_Deny, Level) VALUES ('" . $Permit_or_Deny . "','" . $Level . "');";

    $db->setQuery($query);
    $db->query();

    echo  "<script type='text/javascript'>";
    echo "window.close();";
    echo "</script>";
} else {
    echo '<h4>One Field Is Required!</h4>';
}

?>