即使我按提交后,如何继续显示表单?
<button class="show">Create Team</button>
<form method="post">
<input type="text" name="team_name" />
<input type="submit" value="Submit"></td>
</form>
Jquery:
$(function() {
$(".show").click(function() {
$("form").show();
$(".show").hide();
});
});
答案 0 :(得分:0)
在这种情况下不需要JQuery。你可以使用普通的javascript。
HTML(带内联CSS):
<button id="hide-show-button" onclick="hideshowform()">Create Team</button>
<form method="post" id="team-form" style="display:none;">
<input type="text" name="team_name" />
<input type="submit" value="Submit">
</form>
Javascript(不是JQuery):
var formstate = "shown";
function hideshowform() {
if (formstate == "shown") {
formstate = "hidden";
document.getElementById("hide-show-button").innerHTML="Create Team";
document.getElementById("team-form").style.display="none";
} else {
document.getElementById("hide-show-button").innerHTML="Hide Form";
document.getElementById("team-form").style.display="block";
formstate = "shown";
}
}
或者,如果您不想隐藏表单,请使用以下代码:
HTML(带内联css):
<button id="show-form-button" onclick="showform()">Create Team</button>
<form style="display:none;" method="post" id="team-form">
<input type="text" name="team_name" />
<input type="submit" value="Submit">
</form>
Javascript(不是Jquery):
function showform() {
document.getElementById("team-form").style.display="block";
document.getElementById("show-form-button").style.display="none";
}
如果这个答案对你有所帮助,请考虑进行投票或接受它作为答案。谢谢,祝你的项目好运!