onclick事件处理程序不会触发 [英] onclick event handler doesn't fire
本文介绍了onclick事件处理程序不会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
<div class="modal-footer">
<a class="btn btn-primary" onclick="saveChanges ();">Save changes</a>
</div>
<script type="text/javascript">
$(document).ready(function() {
function saveChanges () {
tinyMCE.triggerSave();
}
...
...
我不确定为什么,但当我点击保存更改链接时没有任何反应,它似乎没有调用 saveChanges
函数。
I'm not sure why but when I click on the "Save changes" link then nothing happens and it does not seem to call the saveChanges
function.
有没有办法我可以删除来自链接的 onClick
事件,只需拥有它就可以点击链接附加 saveChanges()
功能使用 jQuery
?
Is there a way that I could remove the onClick
event from the link and just have it so that the saveChanges()
functionality is attached to the clicking of the link with jQuery
?
推荐答案
该函数应位于全局范围
,如果它在内部范围内,则无法访问 onclick = ...
:
The function should be in the global scope
, if it's in an inner scope it's not accessible to the onclick=...
:
<script type="text/javascript">
function saveChanges () {
tinyMCE.triggerSave();
}
</script>
或 jQuery :
<a class="btn btn-primary"> Save changes</a>
<script type="text/javascript">
$(function(){
$('.btn-primary').click(function(){
tinyMCE.triggerSave();
});
});
</script>
最好给出< a>
id
,如下所示:
<a id="theAnchor"> Save changes</a>
然后......
$(function(){
$('#theAnchor').click(function(){
tinyMCE.triggerSave();
});
});
这篇关于onclick事件处理程序不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文