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 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘