开发者

How to attach event dynamically in javascript?

I am trying overwrite links (transform in ajax links) but when I try to add an开发者_Python百科 event to a tag nothing happens.

My script.

<script type="text/javascript">
    $j(document).ready(function() {
        $j(".will_paginate_styles a").each(function() {
            if (this.innerText.length > 1) {
                this.style.padding = "8px 6px 10px 6px";
                var url = this.href + "&category_id=<%= 1 %>";
                this.href = "#";
                jQuery(this).live("click",
                     function(){
                                new Ajax.Request(url, {asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent('uurmOp9OrgS1CRpcpKdMN9PHlMTt+lkHjhYdNgP+LbQ=')}); return false;
                               }
                );
            }

        });
    });
</script>

How could I attach a event to this tag or transform the link to ajax link? Any suggestions?


I am using JQuery.

This line belongs to prototype library

new Ajax.Request(url, {asynchronous:true, evalScripts:true, parameters:'authenticity_token=' + encodeURIComponent('uurmOp9OrgS1CRpcpKdMN9PHlMTt+lkHjhYdNgP+LbQ=')}); return false;

SO I replace this line for his equivalent in jQuery:

$.ajax(url: "www.myurl.com", data: { data1: "data1", etc: "etc"})

Obviously there are avalaible more options in this method. Read JQuery official documentation

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜