JS处理文本方式.docVIP

  • 22
  • 0
  • 约6.51千字
  • 约 12页
  • 2017-12-14 发布于河南
  • 举报
1 text 属性可设置或返回选项的文本值。 该属性设置或返回的是包含在 option 元素中的纯文本。这个文本会作为选项的标签出现。 语法 optionObject.text=sometext 实例 下面的例子可返回被选选项的文本: html head script type=text/javascript function getOption() { var x=document.getElementById(mySelect) alert(x.options[x.selectedIndex].text) } /script /head body form Select your favorite fruit: select id=mySelect optionApple/option optionOrange/option optionPineapple/option optionBanana/option /select br /br / input type=button onclick=getOption() value=Alert text of selected option /form /body /html 2 textAlign 属性对齐元素中的文本。 语法: Object.style.textAlign=left|right|center|justify 可能的值 值 描述 left 把文本排列到左边。默认值:由浏览器决定。 right 把文本排列到右边。 center 把文本排列到中间。 justify 根据 textJustify 属性对齐文本。 实例 本例对齐一段文本: html head script type=text/javascript function setTextAlign() { document.getElementById(p1).style.textAlign=right; } /script /head body p id=p1This is an example paragraph./p input type=button onclick=setTextAlign() value=Align text / /body /html 3 textDecoration 属性对文本进行修饰。 语法: Object.style.textDecoration=none|underline|overline|line-through|blink 可能的值 值 描述 none 默认。定义标准的文本。 underline 定义文本下的一条线。 overline 定义文本上的一条线。 line-through 定义穿过文本下的一条线。 blink 定义闪烁的文本(无法运行在 IE 和 Opera 中)。 实例 本例给文本设置下划线: html head script type=text/javascript function setTextDecoration() { document.getElementById(p1).style.textDecoration=overline; } /script /head body p id=p1This is an example paragraph./p input type=button onclick=setTextDecoration() value=Set text-decoration / /body /html 4 textIndent 属性缩进元素中的首行文本。 语法: Object.style.textIndent=length|% 可能的值 值 描述 length 定义固定的缩进。默认值:0。 % 定义基于父元素宽度的百分比的缩进。 实例 本例缩进文本: html head script type=text/javascript function setTextIndent() { document.getElementById(div1).style.textIndent=50px; } /script /head body div id=div1 This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. Thi

文档评论(0)

1亿VIP精品文档

相关文档