日期:2014-05-16  浏览次数:20334 次

百度首页js代码,寻求详解
(function() {

//下面为帮助函数******************************************************
var M = navigator.userAgent.indexOf("MSIE") != -1 && !window.opera;//浏览器不是IE 同时不是opera[挪威浏览器] 返回true
var V = (document.compatMode == "BackCompat");//可以用来判断当前页面采用的渲染方式


alert('this browser is '+(M?'IE':'non-IE'));
alert('this browser version is IE5.5? '+V) ;

  function I(C) {//得到一个对象
  return document.getElementById(C)
  }
  function K(C) {//创建一个对象
  return document.createElement(C)
  }
  function S(C) {//消除输入字符串前后的半角和全角空格 
  return String(C).replace(new RegExp("(^[\\s\\t\\xa0\\u3000]+)|([\\u3000\\xa0\\s\\t]+\x24)", "g"), "")
  }
  function U(C) {
  return String(C).replace(new RegExp("[\\s\\t\\xa0\\u3000]", "g"), "")
  }
  function P(X, G, C) {
  if (M) 
{
//ie浏览器下注册事件,attachEvent(事件类型, 处理函数);
X.attachEvent("on" + G, 
(
function(Y) 
{
return function() 
{
C.call(Y)
}
}
)(X))
  } else {
//非ie浏览器下注册事件,对应的函数是addEventListener(事件类型, 处理函数, 使用捕获);
  X.addEventListener(G, C, false)
  }
  }
  function N(C) {
  if (M) {
//ie浏览器
  C.returnValue = false
  } else {
//非ie
  C.preventDefault()//preventDefault方法就是可以阻止它的默认行为的发生而发生其他的事情。 
  }
  }
  function R(G) {
  if (M) 
{
//ie浏览器,为元素添加样式
  var X = document.createStyleSheet();
  X.cssText = G
  } else {
//非ie
  var C = document.createElement("style");
  C.type = "text/css";
  C.appendChild(document.createTextNode(G));
  document.getElementsByTagName("HEAD")[0].appendChild(C)
  }
  }
  function H(Y) {

  var X = document.forms[0];
  for (var G in Y) {
  if (Y[G] == undefined) {
  if (I("bdsug_ipt_" + G)) {
  X.removeChild(I("bdsug_ipt_" + G))
  }
  } else {
  if (!O(G)) {
  X.appendChild(C(G, Y[G]))
  } else {
  O(G).value = Y[G]
  }
  }
  }
  function C(b, Z) {
  var a = K("INPUT");
  a.type = "hidden";
  a.name = b;
  a.id = "bdsug_ipt_" + b;
  a.value = Z;
  return a
  }
  }
  function O(X) {//表单中input的name

  var Y = document.forms[0];//得到第一个表单
  var Z = false;
  var C = Y.getElementsByTagName("INPUT");//得到表单中的所有的input
  for (var G = 0; G < C.length; G++) {
  if (X == C[G].getAttribute("name")) {//循环匹配表单中的所有input,getAttribute("name")表示得到当前对象的name属性
  Z = C[G];
  return Z
  } else {
  Z = false
  }