简体   繁体   中英

javascript function on click doesn't work

This is absurd, I feel like in kindergarten. I've already tried any combination that I could think of, and I just gave up trying.

<script type="text/javascript">
function myFunction(){
 alert("test");
}
</script>


<a href="#" class="love" id="<?php echo $img_id; ?>" onclick="myFunction()">

This is a php file that is being "inserted" in a parent html, but I don't see why this would mess with javascript.

Close out your <a> tag:

<a href="#" class="love" id="<?php echo $img_id; ?>" onclick="myFunction()">TEST</a>

And your code works:

Working Example

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