setAttribute版本:DOM1 返回值:无
语法:
object . setAttribute ( sName , vValue , iFlags ) 
参数:
sName  : 必选项。字符串(String)。指定属性的名称。 
vValue  : 必选项。要赋给属性的值。可以是任何需要的变量类型。 
iFlags  : 可选项。整数值(Integer)。0 | 1 0  : 当属性被设置的时候,对象任何已有的同名属性设置都会被覆盖,而不会考虑它们的大小写。 
1  : 默认值。执行严格考虑字母大小写的属性设置。假如此方法的 iFlags 参数设置为 1 ,则执行 iFlags 参数设置为 0 的 getAttribute 方法时,满足 sAttrName 指定的特性名称不一定能被找到。 
 返回值:
无  说明:
设置指定的属性值。
假如指定的属性尚不存在,则此方法会为对象添加属性并赋值。
请务必小心拼写属性名称。假如你设置 iFlags 参数为 1 ,但是 sName 参数的字母大小写不符合您所期望赋值的属性名称,则此方法的执行结果会是新的属性被建立并赋值。
假如对象有多个名字一样但字母大小写不同的属性,并且 iFlags 参数被设为 0 ,那么只有其中第一个被建立的那一个会被此方法获取。而其他的则会被忽略。
当使用此方法获取 CLASS 属性的值时,需要将 sName 参数指定为 className 。这是 CLASS 属性所对应的 DHTML 特性。

解决方案 »

  1.   

    setAttribute--------------------------------------------------------------------------------DescriptionSets the value of the given attribute. If the attribute is not already present, the method adds the attribute to the element and sets the value. Syntax
    object.setAttribute(attrName , value [, caseSensitive])Parameter Description 
    attrName  String specifying the name of the attribute. 
    value  String, number, or Boolean value to assign to the attribute.  
    caseSensitive  Optional. Boolean value specifying whether to use a case-sensitive search to locate the attribute. If TRUE, the uppercase and lowercase letters in attrName must match exactly those in the attribute name. By default, this parameter is TRUE. Return ValueNo return value. ResBe careful when spelling attribute names. If caseSensitive is TRUE and attrName does not have the same uppercase and lowercase letters as the attribute, this method creates a new attribute. If two or more attributes have the same name (differing only in uppercase and lowercase letters) and caseSensitive is FALSE, this method assigns a value only to the first attribute (the first to be created with this name). All other attributes of the same name are ignored. Applies ToA, ADDRESS, APPLET, AREA, B, BASE, BASEFONT, BGSOUND, BIG, BLOCKQUOTE, BODY, BR, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, COMMENT, DD, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, FORM, FRAME, FRAMESET, H1, H2, H3, H4, H5, H6, HEAD, HR, HTML, I, IFRAME, IMG, INPUT, KBD, LABEL, LEGEND, LI, LINK, LISTING, MAP, MARQUEE, MENU, META, NEXTID, OBJECT, OL, OPTION, P, PLAINTEXT, PRE, S, SAMP, SCRIPT, SELECT, SMALL, SPAN, STRIKE, STRONG, STYLE, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TITLE, TR, TT, U, UL, VAR, WBR, XMP, style 
      

  2.   

    div.style.getAttribute("color");
    div.style.setAttribute('color', '#FF0000');
    div.style.removeAttribute('color');  //去掉某个属性