我想以創建動態的形式,添加到輸入的形式通過按壓按鈕(或圖像) 當我直接把代碼上onclick事件HTML表單onclick事件不調用javascript函數
alert("Hello");
它的工作原理...但是,它不會當我嘗試調用一個JavaScript函數...即使我調用簡單的函數hello(); (以及add())
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript">
function add() {
var container = document.createElement("div");
container.innerHTML = "<input type='text' name='email'><br/>";
document.getElementById('emails').appendChild(container);
}
function hello() {
alert("Hello");
}
</script>
</head>
<body>
<form id="myform" name="myform" action="valid.php" method="POST">
<div id="emails">
<input type='text' name='email' value=''/><br />
</div>
<img width="50px" src="myimage.jpg" onclick='add();'/>
<input type="submit" value="Submit"/>
</form>
</body>
</html>
任何人都能找到原因嗎?
你究竟在哪裏調用函數? – Shomz
我看不到你指定'hello'爲onclick事件處理程序的地方 –
似乎在這裏工作http://jsfiddle.net/j08691/k9g5e/ – j08691