2

我正在尝试一个代码,它将加载一个 iframe onsubmit。我能够做到这一点onchange的文本字段(代码取自某处)。但onsubmit不起作用:

作品

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<meta name="Content-Style-Type" content="text/css">
<title>Example</title>

</head>
<body>
<input value="Song1" onchange="foo.location='song.php?song=blind_willie.mp3'"  style="display:block; margin:auto" type="text">
<iframe name="foo" style="display:block; margin:auto"></iframe>
</body>
</html>

不工作

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">


<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<meta name="Content-Style-Type" content="text/css">
<title>Example</title>

</head>
<body>
<input value="Song1" onsubmit="foo.location='song.php?song=blind_willie.mp3'"  style="display:block; margin:auto" type="Submit">
<iframe name="foo" style="display:block; margin:auto"></iframe>
</body>
</html>
4

3 回答 3

1

Onsubmit 在表单上,​​而不是在提交按钮上,尝试在“onclick”事件中使用 type="button" 代替。

于 2011-06-16T04:49:29.063 回答
1

OnSubmit是一个form事件,所以它不会起作用input

改用type='button'OnClick事件。

于 2011-06-16T04:49:40.077 回答
1

2件事:

onsubmit 属于表单元素,而不是输入,因此您可以将当前输入放在这样的表单中:

<form onsubmit="foo.location='song.php?song=blind_willie.mp3'; return false">
    <input value="Song1" style="display:block; margin:auto" type="Submit" />
</form>

第二件事是您需要从 onsubmit 返回 false ,否则它将尝试刷新页面,因为您没有任何操作。

附带说明一下,这似乎是一种很奇怪的方法。你当然可以这样做:

<input value="Song1" onclick="foo.location='song.php?song=blind_willie.mp3'"  style="display:block; margin:auto" type="Submit" />
于 2011-06-16T04:50:33.277 回答