问题描述
我之前从未这样做过,所以如果我没有充分描述我的问题或者没有使用所有正确的语法,我道歉。
I have never done this before so I apologize if I don't describe my issue good enough or don't use all the right syntax.
我有什么在我的网站上是一个电子邮件表格。用户可以键入消息,以及他们的姓名和其他一些数据。一旦他们填写完表格,他们就可以提交,然后转到我的电子邮箱,一切都很顺利。因为表单中包含JavaScript,所以我自动将其隐藏在CSS中,然后通过JavaScript将其显示出来。这样,如果用户关闭了JavaScript,则不会显示该表单。
What I have on my website is an email form. The user can type in a message, along with their name and some other data. Once they finish filling out the form they can submit it and it goes to my email and all is well. Because the form has JavaScript in it, I automatically had it hidden with CSS and then made it visible through JavaScript. That way if the user has their JavaScript turned off the form won't appear.
并且效果很好。而且我认为它也表现得很好。我在所有本地测试浏览器(Chrome 21,FF 14,IE 9,Opera 12和Safari 5)以及IE 8,7和6的Adobe Browser实验室中进行了检查。在所有这些浏览器中,它看起来很棒。我甚至在我的Android手机和我女朋友的黑莓手机上检查了它。它看起来很好。
And it works great. And I thought it displayed great too. I checked it across all my local testing browsers (Chrome 21, FF 14, IE 9, Opera 12 and Safari 5) as well as through Adobe Browser lab for IE 8, 7 and 6. In all of them it looked fantastic. I even checked it on my Android phone and my girlfriend's Blackberry. It looked fine.
直到我在妈妈的计算机上用IE 8测试它。虽然在Adobe Browserlab中它表示表单显示,但在真实的测试中,表格没有出现。
Until I tested it on my mom's computer with IE 8. Although in Adobe Browserlab it says the form displays, in a real test the form doesn't show up.
您可以自己测试。
问题在于表单id,emailForm。我的表格有这样的标记:
The issue is with the form id, "emailForm". My Form has the markup like so:
<form id="emailForm" method="POST" action="../javascript/email_form.php" onSubmit="return validateForm();">
<label id="emailSubjectLabel">Email Subject*:</label><input class="form" title="Email Subject" type="text" name="subject" id="emailSubject"><br>
<label id="nameLabel">Your Name*:</label><input class="form" title="Your Name" type="text" name="name" id="yourName"><br>
<label id="emailLabel">Your Email:</label><input class="form" title="Your Email Address" type="text" name="email" id="yourEmail"><br>
<label id="messageLabel">Your Message*:</label>
<textarea class="form" title="Write Something..." name="message" id="message" cols="40" rows="5"></textarea>
<input class="button" type="submit" value="Submit">
<p class="error">* required.</p>
</form>
我的CSS有很多代码,但它有关于使表单不可见的问题:
My CSS has a whole bunch of code, but it has this in regards to making the form invisible:
#emailForm, #javaText {
display: none;
}
(注意:#javaText是屏幕上的一些文字也是隐藏的,除非用户安装了JavaScript。它在IE 8中也不起作用。为了简单起见,我没有提到它。)
(note: #javaText is some text on the screen that also is hidden unless the user has JavaScript installed. It also doesn't work in IE 8. Just for simplicity I'm not mentioning it.)
JavaScript看起来像这样: / p>
And the JavaScript looks like this:
document.getElementById("emailForm").style.display = "block";
document.getElementById("javaText").style.display = "inline";
function validateForm() {
//function that validates the form
}
我已将JavaScript放在页面底部,希望它会有所帮助。我已经尝试在主HTML页面上更改内容的样式,我检查了我母亲的JavaScript并启用了它。我只是不知道为什么它不起作用。
I've placed the JavaScript at the bottom of the page, hoping it would help. I've tried changing the style of the content right on the main HTML page, I've checked my mother's JavaScript and it is enabled. I just don't know why it isn't working.
如果有人能告诉我我做错了什么,我会非常感激。这让我头疼了一个星期。
If somebody could tell me what I'm doing wrong, I'd be very thankful. This has been giving me a headache for a week now.
(是的,我告诉她IE很糟糕,她应该选择Chrome,但她之所以没有这是一个完全不同的故事......)
(And yes, I've told her IE sucks and she should go with Chrome, but the reason she doesn't is a whole different story...)
感谢您的帮助。我迫不及待地想知道解决方案是什么!
Thanks for your help. I can't wait to hear what the solution is!
推荐答案
IE8未加载 form_validation。 js
文件,这就是为什么它没有在该文件中运行初始化代码。
IE8 is not loading your form_validation.js
file and that's why it isn't running your initialization code in that file.
您需要将脚本标记上的类型更改为 type =text / javascript
或删除类型完全。您有 type =application / javascript
这是不正确的。
You need to change the type on your script tag to type="text/javascript"
or remove the type entirely. You have type="application/javascript"
which is not correct.
进一步探索后,请参阅以进行更多讨论。
After further exploration, see Why doesn't IE8 recognize type="application/javascript" in a script tag? for more discussion.
这篇关于document.getElementByID在IE 8中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!