0

我有一个点击事件,在事件处理程序中有一个假设返回字符串值的函数

例如:

  $('.customDropDownList li').click(function(){

      var yourCurrentSeasonSelection = selectionReplaced(this);

      //return var yourCurrentSeasonSelection from here.
  });



function selectionReplaced(refT){   
   var valueRegistered = $(refT).find("a[href]").attr('href').replace('#', '');
    ....
   return valueRegistered;
}

单击 yourCurrentSeasonSelection 变量后如何获取返回值?

4

2 回答 2

1

yourCurrentSeasonSelection在点击实际发生之前,您不能“返回” 。您想对该值执行的任何操作都必须单击处理程序中进行。

$('.customDropDownList li').click(function() {
    var yourCurrentSeasonSelection = selectionReplaced(this);

    //do something with yourCurrentSeasonSelection
});
于 2013-11-15T06:39:56.790 回答
1

事件没有返回值。你可以做这样的事情

$(".customDropDownList li").click(function(event){
  selectionReplaced(this);
  event.preventDefault();
});

function selectionReplaced(refT){   
  var link = $(refT).find("a[href]");

  link.attr("href", function(idx, href){
    return href.replace("#", ");
  });
}
于 2013-11-15T06:42:43.477 回答