开发者

calling an ajax function via html

i have an ajax function(with arguments) and i want to call it via html

the calling now is:

<a href='javascript:;' class='vote_down' id='$wordNum'></a>

and the ajax function starts with:

$("a.vote_down").click(function(args){

how do i add 开发者_Python百科the arguments to the html code


Generally the way you do that is to get the value of an HTML element in your click handler:

$("a.vote_down").click(function(){
    var arg1 = $("#argument1").val(); // Gets the argument from the value of an element
    var art2 = $("#argument2").text(); // Gets the argument from the text of an element

    // Do some fancy stuff
});


<a href="#" onclick="javascript:functionName(arg1, arg2);">

Point of note: it's always a good idea to also provide an alternative for those with JavaScript disabled. For example, in your href attribute you could link to a page that has a normal HTML form to submit the vote.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜