JS common knowledge

1. style related

  • Take the line between style
    oDiv.style.width; // This method can only get between the lines styles, get less than among non-line style.
  • Room negated inline style
    (1) var w = getComputedStyle ( oDiv) .width; // IE8 and below are not compatible.
    (2) var w = oDiv.currentStyle [ "width"]; // IE6,7,8 proprietary, but is not compatible with a standard browser.
    (3) Object attribute ----> Object [ "Properties"].

    //兼容处理:
    function getStyle(obj,attr){
     return obj.currentStyle ? obj.currentStyle[attr] : getComputedStyle(obj)[attr];
    }
  • set/getAttribute
oInput.setAttribute("style","background:red");
oInput.getAttribute("style");//返回字符串

oInput.setAttribute(attrName,attrValue);
oInput.getAttribute(attrName);

oInput.getAttribute("class");//IE6,7不兼容,返回null值。
oInput.getAttribute("className");//IE6,7适用,标准浏览器及IE8及以上不兼容。
  • cssText
    oDiv.style.cssText = "width:200px;height:200px;background:red;"

2. Related Properties

(1) innerHTML: Content closing tag
(2) value
(. 3) className
(. 4) the fontSize
(. 5) the src
(. 6) document.write ( " "); document.body.innerHTML = " "

Guess you like

Origin blog.51cto.com/11569511/2417814