【发布时间】:2011-01-30 17:00:50
【问题描述】:
假设我有这套 HTML 标记和 CSS
#CSS
.inputhelp_text { background: #000; color: #fff; }
.nodisplay { display: none; }
<input class="inputhelp" id="firstname" /><span class="inputhelp_text nodisplay" id="help_firstname">Write in your firstname</span>
<input class="inputhelp" id="lastname" /><span class="inputhelp_text nodisplay" id="help_lastname">Write in your lastname</span>
使用 jQuery,我需要将一个函数绑定到所有输入字段(我猜是使用 jQuery 的 EACH 函数),这样当我单击输入字段时,它应该将每个跨度的类切换为仅“inputhelp_text”。我已经让它在每个字段的两个单独的函数中工作,但由于我有很多字段,我知道有更好的方法来解决它。
有什么建议吗?
【问题讨论】:
-
我不习惯 jQuery,所以即使是手动的,事情开始也很慢。 “谢谢”你。
-
这就是为什么阅读文档可能会有用。
标签: jquery html css function each