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>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745163665a4614519.html
评论列表(0条)