简体   繁体   English

HTML输入字段定制

[英]HTML input field customization

I want to make a contact form which simply shows an image if the input that was entered was correct or incorrect. 如果输入的输入正确或不正确,我想制作一张仅显示图像的联系表。 Im trying to only use HTML and CSS to do this. 我试图只使用HTML和CSS来做到这一点。 I know there are a lot of similar posts like this but none give me the answer im looking for. 我知道有很多类似的帖子,但是都找不到我想要的答案。

My html: 我的html:

<div id="contact">
    <div class="formulier">
        <div id="inline">
            <h2>Send us a Message</h2>
            <form id="contact" action="#" method="post" name="contact">
                <label for="email">Your E-mail : </label>
                <input id="email" class="txt" type="email" name="email" />
                <img src="assets/img/NoMark.png" alt="No Mark" height="25" width="24"><br>

                <label for="msg">Enter a Message : </label>
                <textarea id="msg" class="txtarea" name="msg"></textarea><br>

                <button id="send">Send E-mail</button>
            </form>
        </div>
    </div>
</div>

So currently i have an input field followed by an image (in my case by a checkmark or an X). 所以目前我有一个输入字段,后跟一个图像(在我的情况下是一个选中标记或一个X)。 I want my form to switch between the images if the input box with type="email" is correct. 如果输入框的type =“ email”是正确的,我希望表单在图像之间切换。

Thanks in advance, 提前致谢,

thefellowes 研究员

You could try this: 您可以尝试以下方法:

html: 的HTML:

<input id="email" class="txt" type="email" name="email" />
<img class="not-validated" src="assets/img/NoMark.png" alt="Not validated" height="25" width="24">
<img class="valid" src="assets/img/checkmark.png" alt="Valid" height="25" width="24">
<img class="invalid" src="assets/img/cross.png" alt="Invalid" height="25" width="24"><br>

css: CSS:

#email ~ img.not-validated, #email:valid ~ img.valid, #email:invalid ~ img.invalid {
    display: inline-block;
}
#email:valid ~ img.not-validated, #email:invalid ~ img.not-validated, #email:valid ~ img.invalid, #email:invalid ~ img.valid {
    display: none;
}

More on html and css only form validation: http://www.the-art-of-web.com/html/html5-form-validation/ 有关HTML和CSS仅表单验证的更多信息: http : //www.the-art-of-web.com/html/html5-form-validation/

Note: browser support may not be what you need though. 注意:浏览器支持可能不是您所需要的。 Support in IE10+, Firefox 26+, Chrome 31+, Safari 5.1+ (partial support), Opera 19+, IE10.0 mobile (partial support), Blackberry browser 10.0. 支持IE10 +,Firefox 26 +,Chrome 31 +,Safari 5.1+(部分支持),Opera 19 +,IE10.0移动版(部分支持),Blackberry浏览器10.0。 Not supported in iOS safari, Android browser and Opera mini. iOS Safari,Android浏览器和Opera mini不支持。 See: http://caniuse.com/#feat=form-validation 请参阅: http//caniuse.com/#feat=form-validation

You're talking about an input validation. 您正在谈论输入验证。 You can't do it only with css and html, you'll need javascript indeed. 您不能仅使用css和html来做到这一点,实际上确实需要javascript。 This may helps JavaScript Form Validation 这可能有助于JavaScript表单验证

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM