這是我的代碼片段jsfiddle。爲什麼我的onclick事件不起作用?
我想要「+創建論壇」按鈕來顯示窗體,「取消」按鈕來重置窗體並隱藏它,如果您想查看窗體,請刪除「style =」display:none「
我用了很多例子了W3Schools的和我曾嘗試使用寫節目的所有實例和隱藏,工作的復位之一,但它是一個的onclick =「this.reset()」,這是不我想要的東西,因爲我想它隱藏了。
<html>
<body>
<button class="btn btn-default" type="submit" id="createform">+ Create Forum</button>
<div class="form-group" id="createForum">
<form action="forums.php" method="get" id="forumForm" style="display: none">
<label>Forum name:</label>
<input type="text" class="form-control" id="forumName">
<label>Description:</label>
<textarea class="form-control" rows="5" id="description"></textarea>
<button class="btn btn-danger" type="submit" name="create">Crear</button>
<input type="button" value="Reset Form" onclick="clearing()">
</form>
</div>
</body>
<script type="text/javascript">
$("#createform").click(function() {
$("#forumForm").show();
});
function clearing() {
document.getElementById("forumForm").reset();
}
</script>
您正在使用jquery和香草javascript的混合。此外,我會建議不內嵌JavaScript像你有輸入onclick方法「清除」 – Enjayy