-3

单击锚点时如何在 PHP 中获取 id,同时调用 Javascript 函数?

Javascript 函数在 和 时起作用,href="#"并且在使用 时调用 PHP href="index.php?id=1"

单击锚点时,如何同时进行?我也在调用函数 onclick="js()"

echo "<li>" ."<a href='#t.php?id=1' onmousedown='div(2)'>".$pro[$i]."</a>" ."</li>";

     }  
if (isset($_GET['id']))
     {
        echo "HELLO";
     }
4

1 回答 1

0

When a click occurs, the Javascript handler will be fired, then the browser will load the page specified in the href attribute.

If you wish to execute some Javascript before the redirection happens, continue using your onclick event:

<a href="index.php?id=1" onclick="doSomethingInJavascript()">...

Your Javascript function can return false if you wish to cancel the redirection to the PHP page, if necessary.

Also be aware that AJAX calls will allow you to call a PHP script and perform other Javascript functionality, all without loading a new page.

于 2013-05-29T18:01:41.017 回答