使用 "for" 属性转换 IE 特定 javascript
Converting IE specific javascript with "for" attribute
我的页面上有一个表单和一个在 IE 中运行的脚本。我需要让它在 Chrome 中工作。我的代码如下
<script for="Form1" event="onsubmit()" language="JScript">
if (this.text1.value == '')
{
alert ("Please enter the value")
this.text1.focus()
return false
}
this.hiddentext1.value = this.text1.value;
// Disable button
with ($('button1')) {
value = "Processing ...";
disabled = true;
}
return true;
</script>
表格如下:
<form method="post" name="Form1" action="default.asp">
<input type="hidden" name="hiddentext1">
<input type="text" name="text1">
<input type="submit" value="Submit" id="button1">
</form>
它工作正常,正在提交表单。但我还需要让它在 Chrome 中工作,所以我必须摆脱
<script type="text/jscript">
function ProcessField()
{
alert("script gets called");
alert("input value is " & this.text1.value);
if (this.text1.value == '')
{
alert ("Please enter the value")
this.text1.focus()
return false
}
this.hiddentext1.value = this.text1.value;
// Disable button
with ($('button1')) {
value = "Processing ...";
disabled = true;
}
return true;
}
</script>
表格如下:
<form method="post" name="Form1" action="default.asp" onsubmit="return processField();">
<input type="hidden" name="hiddentext1">
<input type="text" name="text1">
<input type="submit" value="Submit" id="button1">
</form>
脚本被调用但显然崩溃了 - "script gets called" 显示了部分但没有触发第二个警报。
我在这里做错了什么?
看起来您将字符串连接的语法与另一种语言混淆了。
alert("input value is " & this.text1.value);
应该是
alert("input value is " + this.text1.value);
您可能会遇到在提交表单之前禁用按钮的问题。 this
是 window
而不是 form
。
function processField(form) //changed to lowercase p, pass in form
{
alert("script gets called");
alert("input value is " + form.text1.value); //changed & to +, updated this to form
if (form.text1.value == '') //updated this to form
{
alert ("Please enter the value")
form.text1.focus() //updated form
return false
}
form.hiddentext1.value = form.text1.value; //updated this to form
// Disable button
with ($('button1')) {
value = "Processing ...";
disabled = true;
}
return true;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form method="post" name="Form1" action="default.asp" onsubmit="return processField(this);"> <!-- pass in this -->
<input type="hidden" name="hiddentext1">
<input type="text" name="text1">
<input type="submit" value="Submit" id="button1">
</form>
我的页面上有一个表单和一个在 IE 中运行的脚本。我需要让它在 Chrome 中工作。我的代码如下
<script for="Form1" event="onsubmit()" language="JScript">
if (this.text1.value == '')
{
alert ("Please enter the value")
this.text1.focus()
return false
}
this.hiddentext1.value = this.text1.value;
// Disable button
with ($('button1')) {
value = "Processing ...";
disabled = true;
}
return true;
</script>
表格如下:
<form method="post" name="Form1" action="default.asp">
<input type="hidden" name="hiddentext1">
<input type="text" name="text1">
<input type="submit" value="Submit" id="button1">
</form>
它工作正常,正在提交表单。但我还需要让它在 Chrome 中工作,所以我必须摆脱
<script type="text/jscript">
function ProcessField()
{
alert("script gets called");
alert("input value is " & this.text1.value);
if (this.text1.value == '')
{
alert ("Please enter the value")
this.text1.focus()
return false
}
this.hiddentext1.value = this.text1.value;
// Disable button
with ($('button1')) {
value = "Processing ...";
disabled = true;
}
return true;
}
</script>
表格如下:
<form method="post" name="Form1" action="default.asp" onsubmit="return processField();">
<input type="hidden" name="hiddentext1">
<input type="text" name="text1">
<input type="submit" value="Submit" id="button1">
</form>
脚本被调用但显然崩溃了 - "script gets called" 显示了部分但没有触发第二个警报。 我在这里做错了什么?
看起来您将字符串连接的语法与另一种语言混淆了。
alert("input value is " & this.text1.value);
应该是
alert("input value is " + this.text1.value);
您可能会遇到在提交表单之前禁用按钮的问题。 this
是 window
而不是 form
。
function processField(form) //changed to lowercase p, pass in form
{
alert("script gets called");
alert("input value is " + form.text1.value); //changed & to +, updated this to form
if (form.text1.value == '') //updated this to form
{
alert ("Please enter the value")
form.text1.focus() //updated form
return false
}
form.hiddentext1.value = form.text1.value; //updated this to form
// Disable button
with ($('button1')) {
value = "Processing ...";
disabled = true;
}
return true;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form method="post" name="Form1" action="default.asp" onsubmit="return processField(this);"> <!-- pass in this -->
<input type="hidden" name="hiddentext1">
<input type="text" name="text1">
<input type="submit" value="Submit" id="button1">
</form>