我想讓一個div位於另一箇中心(垂直和水平),但只能水平居中,而不是垂直居中。你能否讓我知道在我的代碼中如何做到這一點?垂直居中div,然後如何使用jQuery清理輸入文本值?
問題的第二部分是:我一直試圖使用jQuery通過「button1」重置表單的輸入文本值,但那不起作用,你知道爲什麼嗎?
非常感謝!
代碼: 着陸頁
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#button1").click(function() {
$('#inputFirstName').removeAttr('value');
$("#inputFirstName").val('');
});
});
</script>
<style>
#formTable {
border: 1px solid black;
margin: 0 auto;
}
#outer {
width: 100%;
height: 500px;
background-color: gray;
}
#inner {
width: 300px;
height: 300px;
margin: 0 auto;
background-color: yellow;
}
</style>
</h:head>
<h:body>
<div id="outer">
<div id="inner">
<h:form class="signupform">
<p>Sign-up for more:</p>
<table id="formTable">
<tr>
<td>First Name:</td>
<td><h:inputText id="inputFirstName" value="#{visitor.firstName}"/></td>
</tr>
<tr>
<td>Last Name:</td>
<td><h:inputText id="inputLastName" value="#{visitor.lastName}"/></td>
</tr>
<tr>
<td>Email:</td>
<td><h:inputText id="inputEmail" value="#{visitor.email}"/></td>
</tr>
</table>
<p><h:commandButton id="submit" value="Submit" action="#{visitor.registerVisitor()}"/>
<h:outputText id="outputText" value="#{visitor.result}"/></p>
</h:form>
<button id="button1">Empty the div element</button>
</div>
</div>
</h:body>
</html>
非常感謝您的工作,我在選擇您的答案,因爲您先回答。 – user1060551
謝謝。這裏有一個如何清除輸入字段的例子。 http://codepen.io/mikemoney/pen/OWEEGb –
謝謝,但現在它甚至清理提交按鈕。有沒有辦法只清除我想要的?謝謝! – user1060551