gpt4 book ai didi

javascript - 如何使用内联背景颜色样式设置表单输入字段的样式

转载 作者:太空宇宙 更新时间:2023-11-04 12:47:00 25 4
gpt4 key购买 nike

我有一个表单,当我在表单内单击时,我想在其中设置具有特定背景颜色的输入字段的样式。但是,我对此有点麻烦。这是我所拥有的:

<form name="" action="/communicate/#wpcf7-f11-o1" method="post" class="wpcf7-form" novalidate="novalidate">
<div style="display: none;">
<input type="hidden" name="_wpcf7" value="11" /><br />
<input type="hidden" name="_wpcf7_version" value="4.0" /><br />
<input type="hidden" name="_wpcf7_locale" value="" /><br />
<input type="hidden" name="_wpcf7_unit_tag" value="wpcf7-f11-o1" /><br />
<input type="hidden" name="_wpnonce" value="d6b53e1ecd" />
</div>
<p style="color: #fff;">Your Name (required)<br />
<span class="wpcf7-form-control-wrap your-name"><input type="text" name="your-name" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" aria-required="true" aria-invalid="false" /></span>
</p>
<p style="color: #fff;">Your Email (required)<br />
<span class="wpcf7-form-control-wrap your-email"><input type="email" name="your-email" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-email wpcf7-validates-as-required wpcf7-validates-as-email" aria-required="true" aria-invalid="false" /></span>
</p>
<p style="color: #fff;">Subject<br />
<span class="wpcf7-form-control-wrap your-subject"><input type="text" name="your-subject" value="" size="40" class="wpcf7-form-control wpcf7-text" aria-invalid="false" /></span>
</p>
<p style="color: #fff;">Your Message<br />
<span class="wpcf7-form-control-wrap your-message"><textarea name="your-message" cols="40" rows="10" class="wpcf7-form-control wpcf7-textarea" aria-invalid="false"></textarea></span>
</p>
<p><input type="submit" value="Send" class="wpcf7-form-control wpcf7-submit" /></p>
<div class="wpcf7-response-output wpcf7-display-none"></div>
</form>

我想在选择时将输入字段设置为黑色。还有一种我想要的叠加样式,但我稍后会处理。有人能帮忙吗?我没有编写 CSS 规则的奢侈,因为我正在从某人古怪的 WordPress 网站上拼凑一个损坏的表单。更改不会在 <span> 中完成吗?标签?我将字段名称设置为内联 #fff , 并希望使用 #000 进行输入.谢谢!

最佳答案

您可以将其添加到您的 CSS 中:

input:focus, textarea:focus {
background: black;
color: white;
}

更新:

您可以在 <input> 中添加以下代码标签和 <textarea>标签:

onclick="this.style.backgroundColor='black';this.style.color='white'" onblur="this.style.backgroundColor='white';this.style.color='black'"

像这样:

<input type="text" onclick="this.style.backgroundColor='black';this.style.color='white'" onblur="this.style.backgroundColor='white';this.style.color='black'" name="your-subject" value="" size="40" class="wpcf7-form-control wpcf7-text" aria-invalid="false">

    <form name="" action="/communicate/#wpcf7-f11-o1" method="post" class="wpcf7-form" novalidate="novalidate">
<div style="display: none;">
<input type="hidden" name="_wpcf7" value="11" /><br />
<input type="hidden" name="_wpcf7_version" value="4.0" /><br />
<input type="hidden" name="_wpcf7_locale" value="" /><br />
<input type="hidden" name="_wpcf7_unit_tag" value="wpcf7-f11-o1" /><br />
<input type="hidden" name="_wpnonce" value="d6b53e1ecd" />
</div>
<p style="color: #fff;">Your Name (required)<br />
<span class="wpcf7-form-control-wrap your-name"><input onclick="this.style.backgroundColor='black';this.style.color='white'" onblur="this.style.backgroundColor='white';this.style.color='black'" type="text" name="your-name" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" aria-required="true" aria-invalid="false" /></span>
</p>
<p style="color: #fff;">Your Email (required)<br />
<span class="wpcf7-form-control-wrap your-email"><input onclick="this.style.backgroundColor='black';this.style.color='white'" onblur="this.style.backgroundColor='white';this.style.color='black'" type="email" name="your-email" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-email wpcf7-validates-as-required wpcf7-validates-as-email" aria-required="true" aria-invalid="false" /></span>
</p>
<p style="color: #fff;">Subject<br />
<span class="wpcf7-form-control-wrap your-subject"><input onclick="this.style.backgroundColor='black';this.style.color='white'" onblur="this.style.backgroundColor='white';this.style.color='black'" type="text" name="your-subject" value="" size="40" class="wpcf7-form-control wpcf7-text" aria-invalid="false" /></span>
</p>
<p style="color: #fff;">Your Message<br />
<span class="wpcf7-form-control-wrap your-message"><textarea onclick="this.style.backgroundColor='black';this.style.color='white'" onblur="this.style.backgroundColor='white';this.style.color='black'" name="your-message" cols="40" rows="10" class="wpcf7-form-control wpcf7-textarea" aria-invalid="false"></textarea></span>
</p>
<p><input type="submit" value="Send" class="wpcf7-form-control wpcf7-submit" /></p>
<div class="wpcf7-response-output wpcf7-display-none"></div>
</form>

关于javascript - 如何使用内联背景颜色样式设置表单输入字段的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26433124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com