87,915
社区成员
发帖
与我相关
我的任务
分享
$.getJSONP("http://d.360buy.com/area/get?fid=" + areaId + "&callback=getAreaListcallback");
!function ($) {
$.extend({
_jsonp: {
scripts: {},
counter: 1,
charset: "gb2312",
head: document.getElementsByTagName("head")[0],
name: function (callback) {
var name = "_jsonp_" + (new Date).getTime() + "_" + this.counter;
this.counter++;
var cb = function (json) {
eval("delete " + name),
callback(json),
$._jsonp.head.removeChild($._jsonp.scripts[name]),
delete $._jsonp.scripts[name];
};
return eval(name + " = cb"),
name;
},
load: function (a, b) {
var c = document.createElement("script");
c.type = "text/javascript",
c.charset = this.charset,
c.src = a,
this.head.appendChild(c),
this.scripts[b] = c;
}
},
getJSONP: function (a, b) {
var c = $._jsonp.name(b),
a = a.replace(/{callback};/, c);
return $._jsonp.load(a, c),
this;
}
});
}
(jQuery);
//getAreaListcallback
function getAreaListcallback(r) {
currentDom.html(getAreaList(r));
if (currentAreaInfo.currentLevel >= 2) {
currentDom.find("a").click(function () {
if (page_load) {
page_load = false;
}
if (currentDom.attr("id") == "stock_area_item") {
currentAreaInfo.currentLevel = 3;
}
else if (currentDom.attr("id") == "stock_town_item") {
currentAreaInfo.currentLevel = 4;
}
getStockOpt($(this).attr("data-value"), $(this).html());
});
if (page_load) { //初始化加载
currentAreaInfo.currentLevel = currentAreaInfo.currentLevel == 2 ? 3 : 4;
if (currentAreaInfo.currentAreaId && new Number(currentAreaInfo.currentAreaId) > 0) {
getStockOpt(currentAreaInfo.currentAreaId, currentDom.find("a[data-value='" + currentAreaInfo.currentAreaId + "']").html());
}
else {
getStockOpt(currentDom.find("a").eq(0).attr("data-value"), currentDom.find("a").eq(0).html());
}
}
}
}
//getAreaList
function getAreaList(result) {
//var html = "";
//html.push(result);
var html = ["<ul class='area-list'>"];
var longhtml = [];
var longerhtml = [];
if (result && result.length > 0) {
for (var i = 0, j = result.length; i < j; i++) {
result[i].name = result[i].name.replace(" ", "");
if (result[i].name.length > 12) {
longerhtml.push("<li class='longer-area'><a href='#none' data-value='" + result[i].id + "'>" + result[i].name + "</a></li>");
}
else if (result[i].name.length > 5) {
longhtml.push("<li class='long-area'><a href='#none' data-value='" + result[i].id + "'>" + result[i].name + "</a></li>");
}
else {
html.push("<li><a href='#none' data-value='" + result[i].id + "'>" + result[i].name + "</a></li>");
}
}
}
else {
html.push("<li><a href='#none' data-value='" + currentAreaInfo.currentFid + "'> </a></li>");
}
html.push(longhtml.join(""));
html.push(longerhtml.join(""));
html.push("</ul>");
return html.join("");
}
!function ($) {
$.extend({
_jsonp: {
scripts: {},
counter: 1,
charset: "gb2312",
head: document.getElementsByTagName("head")[0],
name: function (callback) {
var name = "_jsonp_" + (new Date).getTime() + "_" + this.counter;
this.counter++;
var cb = function (json) {
eval("delete " + name),
callback(json),
$._jsonp.head.removeChild($._jsonp.scripts[name]),
delete $._jsonp.scripts[name];
};
return eval(name + " = cb"),
name;
},
load: function (a, b) {
var c = document.createElement("script");
c.type = "text/javascript",
c.charset = this.charset,
c.src = a,
this.head.appendChild(c),
this.scripts[b] = c;
}
},
getJSONP: function (a, b) {
var c = $._jsonp.name(b),
a = a.replace(/{callback};/, c);
return $._jsonp.load(a, c),
this;
}
});
}
(jQuery);
//上面的扩展$.getJSONP一定不能少了,要不$.getJSONP就报错了找不到方法
function getInfo(OutId){
$.getJSONP("http://d.360buy.com/area/get?fid=" + areaId + "&callback=getAreaListcallback");
}
$(function(){
//my_location.js现有的代码
});
//原始的Html地址选择器原来的代码......
function getInfo(OutId){
$.getJSONP("http://d.360buy.com/area/get?fid=" + areaId + "&callback=getAreaListcallback");
}
function CurrentAreaInfoInit(proid,cityid,areaid,townid){
currentAreaInfo = {"currentLevel": 1,"currentProvinceId": 1,"currentProvinceName":"北京","currentCityId": 0,"currentCityName":"","currentAreaId": 0,"currentAreaName":"","currentTownId":0,"currentTownName":""};
var ipLoc = getCookie("ipLoc-djd");
ipLoc = ipLoc ? ipLoc.split("-") : [proid || 1, cityid || 72, areaid || 0, townid || 0];
if(ipLoc.length>0&&ipLoc[0]){
currentAreaInfo.currentProvinceId = ipLoc[0];
currentAreaInfo.currentProvinceName = getNameById(ipLoc[0]);
}
if(ipLoc.length>1&&ipLoc[1]){
currentAreaInfo.currentCityId = ipLoc[1];
}
if(ipLoc.length>2&&ipLoc[2]){
currentAreaInfo.currentAreaId = ipLoc[2];
}
if(ipLoc.length>3&&ipLoc[3]){
currentAreaInfo.currentTownId = ipLoc[3];
}
//////////////////
chooseProvince(currentAreaInfo.currentProvinceId);//加载省,需要一级一级加载,不能越级,就是要先初始化省,再到市,县,镇,直接跨级调用镇的数据前面省市县会不匹配
}
//加载广西,桂林,七星区
CurrentAreaInfoInit(20,1726,22885);
function getInfo(OutId){
//var areaId = $(OutId).find("#DivId").text();
//alert(areaId);
$.getJSONP("http://d.360buy.com/area/get?fid=" + areaId + "&callback=getAreaListcallback");
}
求指教~
[/quote]
为什么一定要放函数体里面呢?直接扩展不就好了?而且jquery的jsonp操作只是增加一个script标签到head里面,应该不会影响到你的布局,只可能你后续的操作导致布局错乱
$("#Addr1").mouseover(function () {
//alert("addr1 is OK!");
OutId = "#Addr1";
getInfo(OutId);
});
function getInfo(OutId){
//var areaId = $(OutId).find("#DivId").text();
//alert(areaId);
$.getJSONP("http://d.360buy.com/area/get?fid=" + areaId + "&callback=getAreaListcallback");
}
function getAreaListcallback(r) {
currentDom.html(getAreaList(r));
if (currentAreaInfo.currentLevel >= 2) {
currentDom.find("a").click(function () {
if (page_load) {
page_load = false;
}
if (currentDom.attr("id") == "stock_area_item") {
currentAreaInfo.currentLevel = 3;
}
else if (currentDom.attr("id") == "stock_town_item") {
currentAreaInfo.currentLevel = 4;
}
getStockOpt($(this).attr("data-value"), $(this).html());
});
if (page_load) { //初始化加载
currentAreaInfo.currentLevel = currentAreaInfo.currentLevel == 2 ? 3 : 4;
if (currentAreaInfo.currentAreaId && new Number(currentAreaInfo.currentAreaId) > 0) {
getStockOpt(currentAreaInfo.currentAreaId, currentDom.find("a[data-value='" + currentAreaInfo.currentAreaId + "']").html());
}
else {
getStockOpt(currentDom.find("a").eq(0).attr("data-value"), currentDom.find("a").eq(0).html());
}
}
}
}