Jquery之Bind方法参数传递与接收的三种方法

简介: 方法一、function GetCode(event) { alert(event.data.foo); }$(document).ready(function() { $("#summary").bind("click", {foo:'abc'} ,GetCode); });方法二、函数句柄$("#summary")


方法一、

function GetCode(event)
{
alert(event.data.foo);
}






$(document).ready( function ()
{
$( "#summary" ).bind( "click" , {foo: 'abc' } ,GetCode);
});

方法二、

函数句柄

$( "#summary" ).bind( "click" , function ()
{
GetCode( "abc" )
});




function GetCode(str)
{
}
方法三、

函数闭包

function GetCode(str)
{
return function ()
{
alert(str)
}}


$( "#summary" ).bind( "click" , GetCode( "abc" ));



/**
 * 赞同评论
 */
function commentLike(cid) {
 //alert("innser = " + cid);
 $("#comment-agree-" + cid).unbind("click");
 $.ajax({
  type : "POST",
  url : contextPath + "/comment/commentlike",
  data : "cid=" + cid,
  success : function(success) {
   if (success) {
    //
    $("#comment-agree-" + cid).bind("click",function(){
     commentLike(cid);
    });
    //不能写成:$("#comment-agree-" + cid).bind("click",commentLike(cid)); 不然会变成死循环了
    $('#like_' + cid).text(parseInt($('#like_' + cid).text()) + 1);
    //console.log(success);
   }/* else {
    $('#like_' + cid).text(parseInt($('#like_' + cid).text()) - 1);
    alert(friendTip);
   }*/
  }
 });
}



目录
相关文章
|
7天前
|
JavaScript
jQuery 遍历 方法
jQuery 遍历 方法
21 5
|
2天前
|
前端开发 JavaScript
jQuery - AJAX load() 方法
jQuery load() 方法是简单但强大的 AJAX 方法。
22 6
|
12天前
|
JavaScript
jQuery parentsUntil() 方法
jQuery parentsUntil() 方法
23 10
|
6天前
|
JavaScript 前端开发
jQuery 杂项方法
jQuery 杂项方法
12 2
|
7天前
|
JavaScript
jQuery 效果 方法
jQuery 效果 方法
9 3
|
9天前
|
JavaScript 前端开发
jQuery - noConflict() 方法
jQuery - noConflict() 方法
14 5
|
6天前
|
JSON 前端开发 JavaScript
jQuery AJAX 方法
jQuery AJAX 方法
11 1
|
7天前
|
XML 前端开发 JavaScript
jQuery HTML / CSS 方法
jQuery HTML / CSS 方法
9 2
|
12天前
|
JavaScript
jQuery parents() 方法
jQuery parents() 方法
15 7
|
9天前
|
JavaScript 前端开发
jQuery - AJAX load() 方法
jQuery - AJAX load() 方法
14 2