-2

我有一个具有以下属性的输入变量文本:

<input type="text" style="font-style: italic; color:#808080; font-size: 16px; width: 510px;" id="categ" value="default" name="categ" onfocus="this.value = ''; this.style.color='black'; this.font_weight='normal'">

我想清除格式化样式onfocus。它会清除颜色和文本,但不会清除斜体字重。我也试过 font-weight 和 font.weight

4

3 回答 3

2

你想要font-weight

this.style.fontWeight="normal"

更好的方法是使用 css:

#categ:focus{
    font-weight: normal;
    color:black;
}
#categ{
   font-style: italic; 
   color:#808080; 
   font-size: 16px; 
   width: 510px
}
于 2013-03-07T00:53:51.580 回答
1

如果记忆没有让我失望..

this.style.fontWeight='normal'

然而,正如 bažmegakapa 在他的评论中所说的那样——这真的是很糟糕的做法。您应该为 onfocus 事件创建一个侦听器 - 例如在 jquery 中您可以使用该.focus()方法 - 并具有一个回调函数来更新元素的 css。

纯css会更好!

于 2013-03-07T00:50:03.753 回答
1
this.style.fontWeight='normal'

更新

this.style.fontStyle='normal'

预览 >> jsfiddle 更新 >> jsfiddle

于 2013-03-07T00:58:30.883 回答