duandian8110 2013-02-22 04:38
浏览 91
已采纳

使用onclick运行一个函数

I have a PHP page that has 3 JavaScript functions and uses image maps with 'onclick' to change the image and the map coordinates so that onclick runs the next function.

The code I have so far runs right the way through to the last image of the last function - which I understand. What I am trying to achieve is for the functions to call after the onclick one at a time in the new coordinates.

It is OK if there is a time limit by when each function will call - but before that time limit the onclick can run the next function:

    <img src=<?php echo 'image-start.jpg' ?> width="700" height="400" 
    usemap="#start" class="map" style="border-style:none; margin:0" id="imageX" />


    <map id="start" name="start">
    <area shape="poly"  id="A"  class=""  title="Click to Start"  onclick="myFunction_1()" 
        coords=<?php echo '"'; echo $coords_0; echo '"' ; ?>/>
    <area shape="poly"  id="B"  class=""  title="Click to Start"  onclick="myFunction_1()" 
        coords=<?php echo '"'; echo $coords_0; echo '"' ; ?>/>
    </map>



    <script>
    function myFunction_1() {
         document.getElementById("imageX").src=" <?php echo 'image_1.jpg' ?>  " ;

         document.getElementById("A").coords= <?php echo '"'; echo $coords_1_a; echo '"' ; ?> ;
         document.getElementById("A").onclick= myFunction_2() ;

         document.getElementById("B").coords= <?php echo '"'; echo $coords_1_b; echo '"' ; ?> ;
         document.getElementById("B").onclick= myFunction_2() ;
         }

    function myFunction_2() {
         document.getElementById("imageX").src=" <?php echo 'image_2.jpg' ?>  " ;

         document.getElementById("A").coords= <?php echo '"'; echo $coords_2_a; echo '"' ; ?> ;
         document.getElementById("A").onclick= myFunction_3() ;

         document.getElementById("B").coords= <?php echo '"'; echo $coords_2_b; echo '"' ; ?> ;
         document.getElementById("B").onclick= myFunction_3() ;
         }

    function myFunction_3() {
         document.getElementById("imageX").src=" <?php echo 'image_end.jpg' ?>  " ;
         }
    </script>
  • 写回答

1条回答 默认 最新

  • donglao6169 2013-02-22 05:51
    关注

    You can cause one function to trigger another after a delay with setTimeout() -- for example, adding the following code to myFunction_1 will cause myFunction_2 to run in 5 seconds (5000 milliseconds)

    setTimeout(myFunction_2, 5000)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c