jQuery onClick event

你离开我真会死。 提交于 2019-12-09 16:23:51

问题


Cant seem to get this working. Any help would be great. I am somewhat of a beginner with jquery.

$('#add_button').click(function () {
    $("#add_button").hide();
});

Here is the HTML

<input id='add_button' type='submit' class='add_now' value='' />

Seems simple enough, but clicking on the input does nothing. Is there a different method for targeting inputs? Thanks.


回答1:


Make sure you include jQuery before your script:

<script src="http://code.jquery.com/jquery-latest.js"></script>

And put your code inside a document-ready function:

$(document).ready(function () {
    $('#add_button').click(function () {
        $("#add_button").hide();
    });
});



回答2:


You should add return false; to prevent the browser's default action.




回答3:


Return false from your function.




回答4:


The problem might be that your jQuery is above the form. Try to move it below your HTML.



来源:https://stackoverflow.com/questions/5697058/jquery-onclick-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!