简体   繁体   中英

How to echo a href links with onclick alert php

Problem

When i click this link its alert won't open what should I do ?

My Code

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

必要时你必须转义引号\\' ,试试这个:

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

Try By Following Example.

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

Don't Use Single quote inside alert

Try below example you can do both alert and onclick or either based on return type of function called on click.

<?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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM