如何在单击时更改文本框中文本的字体样式?

发布于 2024-08-04 03:45:36 字数 81 浏览 5 评论 0原文

我怎样才能使用javascript做到这一点?

我的文本框有一个默认值是斜体,但是当单击它时,文本框将被清除,字体样式应该是正常的。

how can i do this using javascript?

my textbox has a default value which is italic but when it is clicked the textbox will be cleared and the fontstyle should be normal.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

断桥再见 2024-08-11 03:45:36

尝试这样的事情:

<input type="text" value="Enter user ID here" 
  style="font-style:italic;" 
  onfocus="this.value='';this.style.fontStyle='normal';" 
  onblur="clickrecall(this,'Enter user ID here');this.style.fontStyle='italic';">

编辑: 当我们在用户输入文本框时清除格式时,我们应该在他出去时将 fontStyle 设置为斜体。

try something like that :

<input type="text" value="Enter user ID here" 
  style="font-style:italic;" 
  onfocus="this.value='';this.style.fontStyle='normal';" 
  onblur="clickrecall(this,'Enter user ID here');this.style.fontStyle='italic';">

EDIT : As we clear the format when user enters the textbox, we should set the fontStyle to italic back when he goes out.

瞄了个咪的 2024-08-11 03:45:36
document.getElementById(inputId).style.fontStyle="normal";
document.getElementById(inputId).style.fontStyle="normal";
梦纸 2024-08-11 03:45:36

在javascript方法中设置样式:

document.getElementById('test').style="font-style:normal;"

set the style in javascript method:

document.getElementById('test').style="font-style:normal;"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文