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 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答