简体   繁体   English

从html / php文件中调用JS函数而无需按钮

[英]Calling JS function from html/php file without button

I'm trying to call my JS function which is in a file called Scripts.js. 我正在尝试调用名为Scripts.js的文件中的JS函数。 I have a php function, but I'm unsure as to whether I need to come out the php function or not as I can't get it to work either way and nothing I've googled is giving a definitive answer as to which it should be so any help would be appreciated! 我有一个php函数,但是我不确定是否需要输出该php函数,因为我无法以任何一种方式使它正常工作,而我搜索过的任何内容都没有给出确切的答案应该是这样,任何帮助将不胜感激!

<?php if(isset($_REQUEST['renameFile']))    
{
    //uses checkboxes from table
    if(isset($_POST['checkbox']))
    {
        $checkedboxes = $_POST['checkbox'];
        $count = count($checkedboxes);
        //echo ("$count");

        /*if($count == 0)
        {
            throw error that something needs to be selected. If implement checkbox hidden then no need to implement 
        }*/

         if($count == 1)
        {?>
            <script type="text/javascript">
                showUpload();
            </script>
            <?php
        }
?>

So I'm calling the function showUpload() in my Scripts.js file which I have defined in my main screen using 因此,我在Scripts.js文件中调用了函数showUpload(),该文件是在主屏幕中使用定义的

<script src ="Scripts.js"> </script>

Which I know works as I've used it elsewhere. 我知道它可以在其他地方使用。

function showUpload()
{
    document.getElementById('fileUpload').style.display = "block";
}

And then this goes on to call a pop up form which I can get to work on a button click so it's just calling it without a button which seems to be an issue. 然后继续调用一个弹出表单,我可以单击按钮进行工作,因此它只是在没有按钮的情况下调用它,这似乎是一个问题。 Thanks! 谢谢!

check following things. 检查以下内容。

  1. include your js file at the top of the file 在文件顶部包含您的js文件

  2. write the script tag out side the php mode. 在php模式下写脚本标签。

  3. make sure the if conditions are true/false as you expect 确保条件是否为真/假

then the code should work fine 那么代码应该可以正常工作

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

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