2011-12-16 80 views
1

我正在修復手機版網站。 http://taxilax.com/phone/選擇服務類型,然後點擊發送信息。 會發生什麼事是,它不重定向到:手機jquery onclick

onclick="form.action='http://taxilax.com/wpcontent/themes/taxi_theme/src/forms/totheairport_process.php';" 

它添加到這個網址:http://taxilax.com/phone/#

任何人有任何想法,爲什麼? 謝謝!

+0

爲什麼要使用內聯JS當你擁有jQuery的可用? – ThiefMaster 2011-12-16 17:43:43

+0

我不允許修改任何內容。我只需要以某種方式解決這個問題。我也看到了這個 – ciprian 2011-12-16 17:49:37

回答

0

您只是更改其操作位置而不張貼表單。您也正在使用鏈接發佈不是最好的想法的表單。您正在將href =「#」放在網址上,這也是您爲什麼在網址上獲得「#」的原因。我會做這完全不同,但迅速幫助您:

onclick="form.action='[put your URL here]';form.submit();" 

這不是在我看來,一個很好的做法,因爲你應該有一個表單提交不會內聯這使代碼更易於維護一個單一的事件處理程序。你也應該使用默認的HTML控件來發布表單。如果你想讓它看起來像一個鏈接,只需樣式一個按鈕或輸入類型提交以取出邊框和顏色等。

你也應該看看jQuery Mobile作爲它非常適合移動的東西。

+0

如果你簽出源代碼,你可以看到所有的jQuery Mobile類添加到元素,但很好的建議:) – Jasper 2011-12-16 18:02:57

1

更jQuery的方式做,這是尼克斯的內聯JavaScript和添加事件處理程序是這樣的:

$('.form-link').bind('click', function (event) { 

    //this will prevent the link from doing what it would natively, so it won't append a hash onto the URL 
    event.preventDefault(); 

    //select the form, if there is more than one form then you will need to alter this selctor, and update it's action as well as trigger a submit 
    $('form').attr('action', '<URL>').trigger('submit'); 
});