2016-07-04 11:57
采纳率: 100%
浏览 56


I have a foreach loop and i want to add a javascript popup within it. I have to code for the loop and the popup box, im just struggling with how to write the link, please see below.

This is the popup link i want to add to my foreach loop:

<a onclick="popupCenter('http://www.example.com', 'myPop1',450,450);" href="javascript:void(0);">CLICK TO OPEN POPUP</a>

so :

foreach($data as $key){

echo "<tr><td>" . $key->value1 . "</td>";
echo "<tr>" . $key->value2 . "</td>";
echo "<tr>" . THIS IS WHERE I WANT TO ADD THE POPUP . "</td>";


  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douyan2470 2016-07-04 12:59

    You have some bad HTML where you open one type of tag but you close another type (tr vs. td).

    I also prefer not to print a lot of HTML with echo. It tends to get messy and hard to read. Try this:

    foreach($data as $key){
        <td><?= $key->value1 ?></td>
        <td><?= $key->value2 ?></td>
        <td><a onclick="popupCenter('http://www.example.com', 'myPop1',450,450);" href="javascript:;">CLICK TO OPEN POPUP</a></td>
    解决 无用
    打赏 举报

相关推荐 更多相似问题