admin管理员组文章数量:1414908
HTML code:
<a href="javascript:void(0);" id="btnSaveComments" runat="server"
onclick="EnterComments();" class="btn btn-sm btn-info no-radius"> Send</a>
JavaScript code:
$(document).ready(function() {
$("#btnSaveComments").click(function(e) {
EnterComments();
e.preventDefault();
});
});
function EnterComments() {
alert("test");
}
When I checked with debugger, it got inside document.ready
but it didn't get inside the function EnterComments
HTML code:
<a href="javascript:void(0);" id="btnSaveComments" runat="server"
onclick="EnterComments();" class="btn btn-sm btn-info no-radius"> Send</a>
JavaScript code:
$(document).ready(function() {
$("#btnSaveComments").click(function(e) {
EnterComments();
e.preventDefault();
});
});
function EnterComments() {
alert("test");
}
When I checked with debugger, it got inside document.ready
but it didn't get inside the function EnterComments
-
put
e.preventDefault();
beforeEnterComments
. – Surinder ツ Commented Jul 16, 2014 at 5:27 - Its working for me jsfiddle/deepakmanwal/8nSSL – Manwal Commented Jul 16, 2014 at 5:27
- it works fine - jsfiddle/43fC3 – Sudharsan S Commented Jul 16, 2014 at 5:27
- did you include jquery.min.js?? – Pranav Commented Jul 16, 2014 at 5:28
- Please make sure your jquery library path – Sudharsan S Commented Jul 16, 2014 at 5:28
3 Answers
Reset to default 2please see the code below :
HTML :
<span class="input-group-btn"><a href="javascript:void(0);" id="btnSaveComments" runat="server"
onclick="EnterComments();" class="btn btn-sm btn-info no-radius"><i class="icon-share"></i> Send</a>
</span>
JS :
function EnterComments() {
console.log("test");
alert("hi");
}
Hope you find it useful.
Demo : http://plnkr.co/edit/Vq0Yi5mu9y0RRK5tIhYt?p=preview
EnterComments()
is called twice here.
Remove onclick="EnterComments();"
and try once.
It should work then
Try this out:
<a href="#" id="anchor_tag" onclick="alert('You are clicked TEST TEXT');">TEST TEXT</a>
SCRIPT CODE:
<script type="text/javascript">
$(document).ready(function(){
$('#anchor_tag').click(function() {
alert('You have clicked test text');
});
enter code here
});
</script>
本文标签: javascriptanchor tag onclick is not workingStack Overflow
版权声明:本文标题:javascript - anchor tag onclick is not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745163665a2645569.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论