我有幾個階段一種形式,我需要做的jQuery提交表單被點擊的PAG的,左邊的鏈接時:jQuery的鏈接提交表單
<a href='?stage=1' class='page-left-btn'>Stage 1</a>
<a href='?stage=2' class='page-left-btn'>Stage 2</a>
<a href='?stage=3' class='page-left-btn'>Stage 3</a>
<a href='?stage=4' class='page-left-btn'>Stage 4</a>
<form id='stageform' action='myurl'>
<!-- form content here which is dynamically dispalyed with php based on the current stage
</form>
現在我有以下的jQuery來提交表單時,單擊鏈接,但它不會工作,我可以爲我的生活工作,爲什麼它不會工作。
$(document).ready(function(){
$('a.page-left-btn').click(function() {
$('#stageform').submit();
});
我能得到這個工作,如果我用一個可點擊的div像這樣:
<div class='page-left-btn'>stage 1</div>
這jQuery的,但我也沒有辦法到新的URL傳遞給網頁?
$(document).ready(function(){
$('.page-left-btn').click(function() {
$('#stageform').submit();
});
我是不正確的選擇鏈接,誰能幫助,我敢肯定它的東西簡單,我只是俯瞰
在此先感謝
到'form'提交,您需要在表格上的'action' ...加上,使用'的preventDefault()'爲了避免你的頁面再次加載,一切都會好起來的。 - 查看是否調用方法的一個簡單方法是在'click'事件中添加'console.log('here');'並打開控制檯...您將看到正在調用正確與否。 – balexandre
點擊一個錨標記,提交提交應該點擊右鍵,而不是重定向到'href' – dreamweiver
thankyou提到的網址都爲您的答覆。也許我從來沒有正確解釋過。我在問什麼是如何選擇與某個類的所有鏈接,即這部分是正確的$('a.page-left-btn')。click(function(){ –