Javascript 在插件函数启动之前调用函数
我有一个函数,可以从某个标记中查找XML文件中的最高值,该标记必须在插件中指定一个默认值。我的问题是我的插件代码在另一个函数之前运行,因此返回空值。我可以在插件之前运行函数Javascript 在插件函数启动之前调用函数,javascript,jquery,xml,Javascript,Jquery,Xml,我有一个函数,可以从某个标记中查找XML文件中的最高值,该标记必须在插件中指定一个默认值。我的问题是我的插件代码在另一个函数之前运行,因此返回空值。我可以在插件之前运行函数get\u Highest\u Property\u Prise(),比如java构造函数吗?或者在插件代码启动之前如何初始化全局变量 var pulgin_Global_Variables = { hight_price: "" }; (function($) { $.fn.SearchProperty = fu
get\u Highest\u Property\u Prise()
,比如java构造函数吗?或者在插件代码启动之前如何初始化全局变量
var pulgin_Global_Variables = {
hight_price: ""
};
(function($) {
$.fn.SearchProperty = function (options) {
var defaults = {
S_MinPrice: 0,
S_MaxPrice: get_Highest_Property_Prise()
};
alert("yo yo "+defaults.S_MaxPrice);
}
})(jQuery);
function get_Highest_Property_Prise()
{
$.get('Data.xml', function (XML_property) {
$(XML_property).find('property').each(function () {
var c_Price = parseInt($(this).find('priceask').text().replace(',', ''));
if (c_Price > pulgin_Global_Variables.hight_price) {
pulgin_Global_Variables.hight_price = c_Price;
}
}); //end of function
});
}
您什么时候调用SearchProperty函数?我将从html页面调用,就像调用其他jquery函数一样…您应该在原始get完成后调用原型函数。在插件开始时调用get_Highest_Property_Prise()是安全的。。。(函数($){get_Highest_Property_Prise();我相信您可以,但不认为有必要将jQuery get调用封装到函数中,除非外部函数实际上正在过滤某些内容或将通知传递给。get我不明白一件事!我设法在get_Highest_Property_Prise()中动态更改全局变量的值函数,但在插件中,它并没有选择那个值!!!我想我必须看更多的代码才能弄清楚你到底想做什么
var pulgin_Global_Variables = {
hight_price: ""
};
$.fn.SearchProperty = function (options) {
var defaults = {
S_MinPrice: 0,
S_MaxPrice: pulgin_Global_Variables.hight_price
};
alert("yo yo "+defaults.S_MaxPrice);
}
})(jQuery);
//here set max price to match your global object
$.get('Data.xml', function (XML_property) {
$(XML_property).find('property').each(function () {
var c_Price = parseInt($(this).find('priceask').text().replace(',', ''));
if (c_Price > pulgin_Global_Variables.hight_price) {
pulgin_Global_Variables.hight_price = c_Price;
}
}); //end of function
}).done(function () {
$(whatever).SearchProperty()
})