当我点击此链接时,它的警报将无法打开我该怎么办?
我的守则
echo "<td><a href='#' onClick='alert('Not an Enumerator!')'>Location</a></td>";
你必须在必要时逃避引用\'
,试试这个:
echo '<td><a href="#" onClick="alert(\'Not an Enumerator!\')">Location</a></td>';
试试下面的例子。
<a href="#" onClick='alert("Not an Enumerator!")'>Location</a>
不要在警报内使用单引号
尝试以下示例,您可以同时执行警报和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>