请问一下我现在在看一个JAVASCRIPT脚本看到如下的语句:
var TB=TB||{};请问各位大侠这个语句是什么意思啊
var TB=TB||{};请问各位大侠这个语句是什么意思啊
解决方案 »
- 如何清除地图覆盖物
- JS获取中10110为什么变成了6呢?
- 帮忙,改一段JS代码,和解释一下JS,高手请进!!!
- 求一个记录IP和访问时间的脚本
- 菜鸟问题
- 在一个div里设置属性style="display:none" 为什么js就获取不到文本框里的值
- document.write('<script language="javascript" type="text/javascript" src="untitled-2.asp"></script>')asp中的写法,在js中怎么写呢?
- 调用有参函数的传值问题
- 帮忙看下这段程序为会返回未定义?
- 在html页面文本域输入js或css不让浏览器执行,输出原文
- 新手javascript 循环问题
- Chrome js 设为主页
这是一个逻辑与操作,当TB真(存在)后面的就不用再执行了,TB就是等于TB了。如果TB为假(可能是undefined,null)时就往下执行,此时TB={}了。
首先,这里的||是或逻辑,与JAVA相同,如果poro不为null(javascript中undefined与null相同),那么||后面的语句不会执行.
第二,{}在js中相当于new Object()
最后,var poro = poro||{};如果porop被定义过且值不为null那么就将值为其本身,如果没有定义过就new它
{
}
;
TB.Header = function()
{
var f = function(v)
{
return typeof(v) != "string" ? v : document.getElementById(v)
}
;
var s = navigator.userAgent.toLowerCase();
var n = /msie/.test(s) && ! / opera / .test(s);
var k = n && ! / msie 7 / .test(s) && ! / msie 8 / .test(s);
var g =
{
getCookie : function(w)
{
var v = document.cookie.match("(?:^|;)\\s*" + w + "=([^;]*)");
return(v && v[1]) ? decodeURIComponent(v[1]) : ""
}
, parseQueryParams : function(B)
{
var y =
{
}
;
var w = B.split("&");
for(var z = 0, A = w.length; z < A; ++ z)
{
var x = w[z], C = x.search("=");
var D = x.substring(0, C);
var v = x.substring(C + 1, x.length);
y[decodeURIComponent(D)] = decodeURIComponent(v)
}
return y
}
, trim : function(v)
{
return v.replace(/^\s+|\s+$/g, "")
}
, hasClass : function(w, v)
{
w = f(w);
if( ! w || ! v || ! w.className)
{
return false
}
return(" " + w.className + " ").indexOf(" " + v + " ") > - 1
}
, addClass : function(w, v)
{
w = f(w);
if( ! w || ! v)
{
return
}
if(this.hasClass(w, v))
{
return
}
w.className += " " + v
}
, removeClass : function(w, v)
{
w = f(w);
if( ! this.hasClass(w, v))
{
return
}
w.className = w.className.replace(new RegExp(v, "g"), "");
if( ! this.trim(w.className))
{
w.removeAttribute(n ? "className" : "class")
}
}
, addEvent : function(x, w, v)
{
x = f(x);
if( ! x || ! w || typeof(v) != "function")
{
return
}
if(x.addEventListener)
{
x.addEventListener(w, v, false)
}
else
{
if(x.attachEvent)
{
x.attachEvent("on" + w, v)
}
}
}
, stopEvent : function(v)
{
if(v.stopPropagation)
{
v.stopPropagation()
}
else
{
v.cancelBubble = true
}
if(v.preventDefault)
{
v.preventDefault()
}
else
{
v.returnValue = false
}
}
, escapeHTML : function(w)
{
var x = document.createElement("div");
var v = document.createTextNode(w);
x.appendChild(v);
return x.innerHTML
}
}
;
var t = g.getCookie("_nk_");
var i = g.getCookie("uc1");
var d = g.parseQueryParams(i);
var p = g.getCookie("_l_g_") && t;
var o = parseInt(d._msg_) || 0;
var j = new Date().getTime();
var c = document.getElementsByTagName("script");
var q = c[c.length - 1].getAttribute("version") == "co";
var r = (document.location.href.indexOf("https://") === 0);
function a(x)
{
x = f(x);
if( ! x)
{
return
}
var w = x.children[1];
if( ! w)
{
return
}
if( ! r)
{
var v = document.createElement("iframe");
v.src = "about: blank";
v.className = "menu-list";
v.style.border = "none";
x.insertBefore(v, w); x.iframe = v
}
x.menulist = w;
x.onmouseenter = function()
{
g.addClass(this, g.hasClass(this, "forum-v2") ? "forum-hover" : "hover"); if(r)
{
return
}
this.iframe.style.height = (parseInt(this.menulist.offsetHeight) - 5) + "px";
this.iframe.style.width = this.menulist.offsetWidth
}
;
x.onmouseleave = function()
{
g.removeClass(this, g.hasClass(this, "forum-v2") ? "forum-hover" : "hover")
}
}
function m(y, x, v)
{
var w = document.createElement("option");
w.innerHTML = y;
w.value = x;
w.className = v || "";
return w
}
code]
{
var x = f(z);
if( ! x)
{
return
}
var y = x.q;
if( ! y)
{
return
}
var w = x.elements.search_type;
var v = x.elements.cat;
v.appendChild(m(" \u6570\u5b57\u7535\u5f71/\u7535\u89c6\u5267/\u7efc\u827a", "special0", "S"));
v.appendChild(m(" \u7535\u5b50\u6742\u5fd7/\u65f6\u5c1a\u751f\u6d3b/\u5a31\u4e50\u524d\u6cbf", "special1", "S"));
g.addEvent(w, "change", function()
{
if(w.value == "dating")
{
g.addClass(v, "hidden")
}
else
{
g.removeClass(v, "hidden")
}
}
);
g.addEvent(x, "submit", function(G)
{
var C = w.value;
if(C == "item" && y.value == "" && v.value == "")
{
x.action = "http://list.taobao.com/browse/cat-0.htm"
}
else
{
if(v.value.indexOf("special") > - 1)
{
x.method = "post";
x.action = ["http://video.taobao.com/searchlist.php", "http://zazhi.taobao.com/search"][v.value.replace("special", "")] + "?q=" + x.q.value
}
else
{
if(C == "mall")
{
x.action = "http://list.mall.taobao.com/search_dispatcher.htm"
}
else
{
if(C == "shop")
{
var E = "";
if(x.elements.page_type)
{
E = x.elements.page_type.value
}
var F = 3;
if(E === "FP")
{
F = 1
}
else
{
if(E === "SRP")
{
F = 2
}
}
if( ! x.elements.stat)
{
if(n)
{
var B = document.createElement('<input name="stat" >')
}
else
{
var B = document.createElement("input");
B.name = "stat"
}
B.type = "hidden";
x.appendChild(B)
}
x.elements.stat.value = F;
if( ! x.elements.catName)
{
if(n)
{
var D = document.createElement('<input name="catName" >')
}
else
{
var D = document.createElement("input");
D.name = "catName"
}
D.type = "hidden";
x.appendChild(D)
}
x.elements.catName.value = v[v.selectedIndex].innerHTML.replace(" ", "");
x.action = "http://shopsearch.taobao.com/browse/shop_search.htm"
}
else
{
if(C == "dating")
{
if(y.value == "")
{
x.action = "http://dating.taobao.com"
}
else
{
x.action = "http://dating.taobao.com/search_question.htm"
}
}
else
{
if(C == "global")
{
x.promote.value = "2097152"
}
else
{
if(C == "auction")
{
x.atype.value = "a";
x.isnew.value = "1,3"
}
}
}
}
}
}
}
var H = v.options[v.selectedIndex];
if( ! H || ! H.className)
{
return
}
var A = H.className.split("^");
if( ! A || A.length < 2)
{
return
}
x.elements.prop.value = A[0];
x.elements.ppath.value = A[1]
}
)
}
function b(C)
{
var z = f(C);
if( ! z)
{
return
}
var A = z.q;
if( ! A)
{
return
}
if( ! (window.TB && TB.Suggest))
{
return
}
var w = new TB.Suggest(A, "http://suggest.taobao.com/sug",
{
resultFormat : ""
}
);
var B = z.ssid;[/