drsrq26482 2014-03-10 15:41
浏览 303
已采纳

在php中回显的html <a>标签中执行javascript弹出窗口

the flow is: a php page calls an ajax function that displays a list of user in a table without refreshing the pages. in this table, i put a delete and edit link. I have no problem with the delete link however, i'm stuck at the edit link.

what I'm trying to do is, when a user click edit link, there will appear a popup window, there, they can update the details of the user, but it appears that my popup window is not appearing.

the javascript function is:

<script type="text/javascript">
function newWindow(url) { 
var x,y;
x = screen.width-35;
y = screen.height-30;
var win =       window.open(url,'glossaryWindow','toolbar=no,directories=no,width=500,height=500'+
        'screenX=0,screenY=0,top=0,left=0,location=no,status=no,scrollbars=no,resize=yes,menubar=no');
    }

i put the function at the top of the page.

this is the php code to call java function in html tag

echo "<td>" . '<a href="javascript: newWindow("/test/HTMLPages/popup_update_user.html")">edit</a>' . "</td>";

is it possible??

i checked it its my URL that wrong, but that is not the problem. the popup does not appear at all. i need advise on this matter.

UPDATE:

this is the correct code for calling javascript in tag within php:

 <?php
    echo "<td>" . "<a href=\"#\" onclick=\"newWindow('popup_update_user.html')\">edit</a>". "</td>"; ?>

:D

  • 写回答

1条回答 默认 最新

  • douji8017 2014-03-10 15:59
    关注

    The problem is that in the echo you are opening and closing the statement before calling the javascript function.

    And don't call the function in the "href", call it from "onclick".

    Try this:

    echo "<td> <a href=\"#\" onclick=\"newWindow('/test/HTMLPages/popup_update_user.html')\">edit</a></td>";
    

    EDIT: Working example

    <!DOCTYPE html>
    <html>
        <head>
            <script type="text/javascript">
                function newWindow(url) { 
                var x,y;
                x = screen.width-35;
                y = screen.height-30;
                var win =       window.open(url,'glossaryWindow','toolbar=no,directories=no,width=500,height=500'+
                        'screenX=0,screenY=0,top=0,left=0,location=no,status=no,scrollbars=no,resize=yes,menubar=no');
                    }
        </script>
        </head>
        <body>
            <table>
                <tr>
                    <?php
                    echo "<td> <a href=\"#\" onclick=\"newWindow('/test/HTMLPages/popup_update_user.html')\">edit</a></td>";
                    ?>
                </tr>
            </table>
        </body>
    </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)