如何使用onclick alert php回显href链接

问题描述 投票:-5回答:3

问题

当我点击此链接时,它的警报将无法打开我该怎么办?

我的守则

echo "<td><a href='#' onClick='alert('Not an Enumerator!')'>Location</a></td>";
php html css
3个回答
1
投票

你必须在必要时逃避引用\',试试这个:

echo '<td><a href="#" onClick="alert(\'Not an Enumerator!\')">Location</a></td>';

0
投票

试试下面的例子。

<a href="#" onClick='alert("Not an Enumerator!")'>Location</a>

不要在警报内使用单引号


0
投票

尝试以下示例,您可以同时执行警报和onclick,也可以基于单击时调用的返回函数类型。

<?php
    echo "<td><a href='test.php' onclick='return test_click();'>Location</a></td>";
?>

<script type="text/javascript">
    function test_click(event){
        alert("Inside this function");
        return true;
    }
</script>
© www.soinside.com 2019 - 2024. All rights reserved.