无论出于何种原因,我都无法在IE9中使用以下代码,但它适用于Firefox,Chrome和Opera:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Laughing Man Productions²-Administrator Portal</title>
<!--[if !IE 9]> <!--><link rel="stylesheet" type="text/css" href="http://www.lmpgames.com/WEB401/W2/css/login_page.css"/><!--<![endif]-->
<!--[if IE 9]>
<link rel="stylesheet" type="text/css" href="http://www.lmpgames.com/WEB401/W2/css/login_page_IE.css"/>
<![endif]-->
</head>
<body>
<div class="login_bg">
<form action="" method="post" enctype="multipart/form-data">
<fieldset class="fset">
<div class="username_text">
Username/Email Address:
<span class="username_field">
<input name="txtbUName" type="text" style="background-color:#DDDDDD;" value="Username" size="20" maxlength="60" />
</span>
</div><br/>
<div class="password_text">
Password:
<span class="password_field">
<input name="txtbPWord" type="password" style="background-color:#DDDDDD;" value="Password" size="20" maxlength="16" />
</span>
</div><br/>
<div class="sub">
<input name="btnSubmit" type="button" onclick="formatUName(this.form)" value="Submit" />
</div>
<textarea name="txtaFOutput" class="txta" cols="1" rows="1">
</textarea>
</fieldset>
</form>
</div>
<script type="application/javascript">
function formatUName(form)
{
//Set up variables and references for use later on
var button = form.btnSubmit;
var txta = form.txtaFOutput;
var username = form.txtbUName;
var password = form.txtbPWord;
var uName = "default";
var pWord = "";
uName = username.value; //Obtain the value of the username field on submit
//Then remove spaces from the value and change all letters to uppercase
uName = uName.replace(/\s+/g, '');
uName = uName.toUpperCase();
//Finally print the formatted username to the textarea
txta.value = uName + " is your username";
}
</script>
</body>
</html>
当我在IE中加载页面并点击提交时,没有任何反应。我已经尝试将.value更改为innerHTML和innerText,但它们都没有在IE中工作。
编辑:
在摆弄IE之后我终于设法让调试运行并且它吐出了这个错误:
行:23 错误:无法获取属性'appendChild'的值:object为null或undefined
编辑2:
忽略之前的错误。 IE允许Vuze通过我不知道Vuze安装的插件注入Javascript代码。禁用它们,现在新的错误消息是关于我的函数名称:
第35行: 属性“formatUName”的值为null或undefined,而不是Function对象
答案 0 :(得分:1)
当我在IE中运行时,JavaScript工作正常,但表单不提交。如果这是您面临的问题,原因是:
<input name="btnSubmit" type="button" onclick="formatUName(this.form)" value="Submit" />
将type="button"
更改为type="submit"
。如果表单中的type="button"
缺少显式提交按钮,则浏览器行为无法预测。
答案 1 :(得分:0)
在HTML中,<!-- comment -->
是评论的正确语法。
另一方面,Javascript使用ANSI C标准评论,// comment
和/* comment */
。
您需要更改:
function formatUName(form)
{
<!-->Set up variables and references for use later on
var button = form.btnSubmit;
var txta = form.txtaFOutput;
var username = form.txtbUName;
var password = form.txtbPWord;
var uName = "default";
var pWord = "";
uName = username.value; <!--> Obtain the value of the username field on submit
<!--> Then remove spaces from the value and change all letters to uppercase
uName = uName.replace(/\s+/g, '');
uName = uName.toUpperCase();
<!--> Finally print the formatted username to the textarea
txta.value = uName + " is your username";
}
要:
function formatUName(form)
{
// Set up variables and references for use later on
var button = form.btnSubmit;
var txta = form.txtaFOutput;
var username = form.txtbUName;
var password = form.txtbPWord;
var uName = "default";
var pWord = "";
uName = username.value; // Obtain the value of the username field on submit
// Then remove spaces from the value and change all letters to uppercase
uName = uName.replace(/\s+/g, '');
uName = uName.toUpperCase();
// Finally print the formatted username to the textarea
txta.value = uName + " is your username";
}
答案 2 :(得分:0)
多个答案都有难题。起初我得到的错误是由于一个Vuze插件,IE允许将Conduit Javascript注入我的所有网页。第二个错误是Internet Explorer本身并且没有任何理由喋喋不休。
在测试代码开始工作之后停止响应后重启IE后,几乎。还有一个问题,这是由纳撒尼尔建议将btnSubmit从一种按钮改为一种提交类型引起的。这导致我所有浏览器中的代码停止工作;文本区域无法正确更新其值。
将类型更改回按钮后,代码适用于所有经过测试的浏览器:IE9 / Firefox 18.1 / Opera 12.15 / Chrome 28.