简体   繁体   English

Javascript函数无法调用onclick吗?

[英]Javascript function is not getting called onclick?

Can anyone see why this is not working? 谁能看到为什么这行不通?

I have a javascript function called addexercise() 我有一个名为addexercise()的JavaScript函数。

<a href="#myModal_addexercise" onclick="addexercise('{{ $workout->name }}', '{{ $workout->workout_id }}'); return false;" role="button" data-toggle="modal" class="btn btn-success">
    Add Exercises
</a>    

When I click the button Add Exercises it does work and the modal opens up but the onclick is not working. 当我单击添加练习按钮时,它确实起作用并且模态打开,但是onclick不起作用。

Here is my JS I have at the end of the file: 这是我在文件末尾的JS:

<script>
function addexercise(name, workout_id) {
    alert(name);
    $('#modal-workout-name').html(name);
}
</script>

Any ideas what I am doing wrong? 有什么想法我做错了吗?

It does'nt appear that you are doing anything wrong, and next time try and put your code inside of an online editor, it will help you debug it before you ask the question. 看来您做错了什么,下次尝试将代码放入在线编辑器中时,它将在您提出问题之前帮助您调试它。 This time, someone did it for you. 这次,有人为您做了。

Click here to see your unchanged code working: 单击此处查看未更改的代码正常工作:

http://codepen.io/nicholasabrams/pen/Pwwrwj http://codepen.io/nicholasabrams/pen/Pwwrwj

<a href="#myModal_addexercise" onclick="addexercise('{{ $workout->name }}', '{{ $workout->workout_id }}'); return false;" role="button" data-toggle="modal" class="btn btn-success">
    Add Exercises
</a>

<div id="modal-workout-name"></div>

function addexercise(name,workout_id) {
    alert(name);
    $('#modal-workout-name').html(name);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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