duancongduo4109 2018-04-15 17:11
浏览 49
已采纳

根据php中数组的大小更改html代码

Hi i have an array with some Urls and Html code for open this webs in others tabs. But the array dynamically changes the amount of Urls it contains. How can I change the Html code depending on the number of Urls that my array contains?

Code:

<?php
//$myarray can change dinamicaly the amount of urls contains
$myarray=array('www.google.com','www.piza.com','www.5.com');
?> 

Now in my HTML code I have the code for open a tab, but i need open the array numbers of urls. In this case I need window.open('') three times.

<p><a href='#'
onclick='window.open('');
>Click to open webs</a></p>
  • 写回答

2条回答 默认 最新

  • dqjjw04440 2018-04-15 17:27
    关注
    <?php
    //$myarray can change dinamicaly the amount of urls contains
    $myarray=array('www.google.com','www.piza.com','www.5.com');
    
    $windowsOpen = '';
    foreach ($myarray as $value) {
        $windowsOpen .= "window.open('$value', '_blank');";
    }
    ?> 
    
    //now in my HTML code I have the code for open a tab, but i need open the array numbers of urls. In this case I need 'window.open('')' three times.
    <p><a href='#' onclick="<?= $windowsOpen; ?>">Click to open webs</a></p>
    

    Few things you should know, the URLs need to start with 'http://' or 'https://' in order to be an external link, if not it be considered as an internal link. Moreover, most of the browsers will block the window.open if it is more than one as spam.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化