我需要根据文本值更改输入class
。当value
为空时,它应该是默认值,当有value
时,它应该将类更改为inputtext
。如何根据输入文字更改班级名称
<style>
.inputnotext{ background:#ddd; }
.inputtext{ background:transparent } /* when their is text */
</style>
<form>
<input class="inputnotext" type="text" name="firstname" /><br />
<input class="inputnotext" type="text" name="lastname" />
</form>
<script>
/* script to write ??? */
</script>
你到目前为止尝试过什么?堆栈溢出是为了帮助修复错误和问题,而不是为您编写代码。 –
你使用jQuery或任何其他库吗? – Variant