运行 Javascript onFocus - 更改 DIV html 文本
目前,我正在尝试设置我的联系表单,以便在输入无效电子邮件时给出错误消息。当提交空白或不正确的电子邮件时,页面应执行以下操作:
- 注册文本更改为“重试”
- 输入字段中出现红色文本,说明“输入的地址无效”
当用户将焦点放在输入字段上,或按“重试';所有表单元素都应返回到其原始状态。我已经能够使用 onFocus 方法将文本从红色变为黑色。我尝试创建一个名为 Reset 的小型 JavaScript,我希望将 DIV 文本从“重试”更改回“注册”。
我确信我的问题与 Javascript 有关。有人能指出我正确的方向吗? :)
Currently I am trying to setup my contact form to give an error message when an invalid email is entered. When a blank or incorrect e-mail is submitted the page should do the following:
- Sign Up text changes to 'Retry'
- Red text appears within input field stating 'Address entered not valid'
When the user focuses on the input field, or presses 'retry'; all the form elements should go back to their original state. I have been able to get the text to change from red to black using the onFocus method. I attempted to create a small little javascript named reset, which I hoped to change the DIV text from 'Retry' back to 'Sign Up'.
I'm certain my issue is with the Javascript. Can someone point me in the right direction? :)
For code reference:
http://itsmontoya.com/work/playdeadcult/indextest.php
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一种方法是使用 html:
和 JavaScript:
JS Fiddle demo。
One way of doing this is, with the html:
And the JavaScript:
JS Fiddle demo.
试试这个:
Try this instead:
这只是您需要帮助的 Reset() 函数的注释掉块吗?如果是这样,您可以尝试它的 jQuery 版本,因为无论如何您都加载了 jQuery =)
以下是您的 Reset() 函数,它将文本颜色更改为红色:
以下是您的 Blur() 函数,它将文本颜色更改为黑色。将此附加到您的电子邮件输入文本框,您应该进行设置:
Is it just the commented out block of your reset() function what you need help with? If so, you can try the jQuery version of it since you have jQuery loaded anyway =)
The following is for your reset() function which changes text color to red:
The following is for your blur() function which changes text color to black. Attach this to your email input text box as well and you should be set: