有一個與它內部的形式在我的網站div標籤如下內動態生成表單:使用document.innerHTML到div標籤
<div class="col-1">
<h4>Login</h4>
<form id="login-form" action="https://mydomain.com/customer/account/loginPost/" method="post">
<fieldset>
<p>Already registered? Please log in below:</p>
<ul class="form-list">
<li>
<label for="login-email">Email Address</label>
<div class="input-box">
<input type="text" class="input-text required-entry validate-email" id="login-email" name="login[username]" value="" />
</div>
</li>
<li>
<label for="login-password">Password</label>
<div class="input-box">
<input type="password" class="input-text validate-password required-entry" id="login-password" name="login[password]" />
</div>
</li>
</ul>
</fieldset>
<div class="buttons-set form-buttons btn-only">
<button type="button" class="button" onclick="loginForm.submit()"><span><span>Login</span></span></button>
<a href="https://mydomain.com/customer/account/forgotpassword/">Forgot your password?</a>
</div>
</form>
</div>
的表單提交功能罰款,直到我試圖生成在「col-1」div標籤上使用.innerHTML在div標籤內完全相同的內容。我使用.innerHTML用下面的替換「COL-1」的HTML:
<h4>Login</h4>
<form id="login-form" action="https://mydomain.com/customer/account/loginPost/" method="post">
<fieldset><p>Already registered? Please log in below:</p>
<ul class="form-list">
<li>
<label for="login-email">Email Address</label>
<div class="input-box">
<input class="input-text required-entry validate-email" id="login-email" name="login[username]" value="" type="text">
</div>
</li>
<li>
<label for="login-password">Password</label>
<div class="input-box">
<input class="input-text validate-password required-entry" id="login-password" name="login[password]" type="password">
</div>
</li>
</ul>
</fieldset>
<div class="buttons-set form-buttons btn-only">
<button type="button" class="button" onclick="loginForm.submit()">
<span><span>Login</span></span>
</button>
<a href="https://mydomain.com/customer/account/forgotpassword/">Forgot your password?</a>
</div>
</form>
爲什麼提交按鈕(或就此按下Enter鍵),當它從.innerHTML產生不提交表單?我檢查了在Firefox中生成的HTML,它與原始HTML完全相同(因爲它應該是),但不會提交...
僅供參考,實際調用.innerHTML來替換在「COL-1」 div標籤內的HTML:
loginFormDivTag.innerHTML='<h4>Login</h4><form id="login-form" action="https://mydomain.com/customer/account/loginPost/" method="post"><fieldset><p>Already registered? Please log in below:</p><ul class="form-list"><li><label for="login-email">Email Address</label><div class="input-box"><input type="text" class="input-text required-entry validate-email" id="login-email" name="login[username]" value="" /></div></li><li><label for="login-password">Password</label><div class="input-box"><input type="password" class="input-text validate-password required-entry" id="login-password" name="login[password]" /></div></li></ul></fieldset><div class="buttons-set form-buttons btn-only"><button type="button" class="button" onclick="loginForm.submit()"><span><span>Login</span></span></button><a href="https://mydomain.com/customer/account/forgotpassword/">Forgot your password?</a></div></form>';
我的最終目標是要增加一個「的onsubmit」方法的形式,有更簡單的方法來做到這一點?也許用jQuery?
真棒,完美的建議,解決了。 – nicktendo 2011-03-22 23:08:51