[英]JQUERY: How do you pass a function as a parameter to $()?
How do you pass a function as a parameter to $()? 如何将函数作为参数传递给$()? For example
例如
function autoplace(map){
// do something with map
};
var map = "Wassup";
$(autoplace(map)); // how to pass a function which takes a parameter, as a paramter to $()
Reference: http://api.jquery.com/jQuery/ 参考: http : //api.jquery.com/jQuery/
$()
takes in different types of parameters in different situations. $()
在不同情况下采用不同类型的参数。
So the point should be what your autoplace()
function is returning . 所以重点应该是您的
autoplace()
函数返回的内容 。 Then what returns gets passed into $()
然后返回的收益将传递给
$()
Example: 例:
function autoplace(map) {
var mapSelector = '#map_' + map,
$map = $(mapSelector);
// do something with map
// return something that's suitable for $()
// Just an example
return mapSelector; // In this example, mapSelector ends up being '#map_Wassup'
}
var $myMap = $( autoplace('Wassup') );
// The result will be equivalent to $('#map_Wassup')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.