它在表單中使用實際的提交按鈕而不是像提交按鈕那樣的超鏈接會更有意義。如果您想更多地控制顯示/格式,可以使用<input type="submit">
或<button type="submit">
。
如果您在使用非提交按鈕(如超鏈接)設置,那麼這將是最好給表單自身的ID:
<form method="post" id="frm_no_kids" name="frm_no_kids" class="getstarted" action="step1.php">
<input type="hidden" id="price_value" name="fee" value="<?php echo encrypt(499); ?>">
<input type="hidden" id="divorce_type" name="divorce_type" value="no_kids">
<a class="btn border-btn yellow-btn started-hover" title="Get Started" href="javascript:document.getElementById('frm_no_kids').submit();">Get Started </a>
</form>
正如在評論中提到的,使用事件偵聽器要好得多:
HTML:
<form method="post" id="frm_no_kids" name="frm_no_kids" class="getstarted" action="step1.php">
<input type="hidden" id="price_value" name="fee" value="<?php echo encrypt(499); ?>">
<input type="hidden" id="divorce_type" name="divorce_type" value="no_kids">
<a id="frm_no_kids_submit" class="btn border-btn yellow-btn started-hover" title="Get Started" href="#">Get Started </a>
</form>
JS:
document.getElementById("frm_no_kids_submit").addEventListener("click", function(){
document.getElementById("frm_no_kids").submit();
});
不要使用內聯事件那樣,這是不好的做法。使用外部事件處理程序 –
但現在,只要給我一個解決這個錯誤的方法。 – neha910
@ neha910你應該積極採納建議。 – Tiger