dtkl55257 2014-12-10 10:34
浏览 43

从没有按钮的html / php文件调用JS函数

I'm trying to call my JS function which is in a file called Scripts.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 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

<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!

  • 写回答

1条回答 默认 最新

  • douyinbo3361 2014-12-10 10:45
    关注

    check following things.

    1. include your js file at the top of the file

    2. write the script tag out side the php mode.

    3. make sure the if conditions are true/false as you expect

    then the code should work fine

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名