怎样用js取得/设置表格的所有属性?

我看到有人用setAttrib()函数,具体怎么用?
怎么取得/设置所选表格的所有属性


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 特性。

 

E文:

 

setAttribute

--------------------------------------------------------------------------------

Description

Sets 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 Value

No return value.

Remarks

Be 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 To

A, 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

 

怎样取得属性,用getAttrib()?

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值