2010-01-20 41 views
-2

由於某些原因,它不會改變論壇的行爲。我有一些代碼改變形式的作用一個按鈕被點擊時:jQuery操作表單

function changeForm(event){ 
    alert("Before: "+jQuery("#franchiseform").attr("action")); 
    jQuery("#franchiseform").attr("action", "franchisepreview.php"); 
    alert("After: "+jQuery("#franchiseform").attr("action")); 
    jQuery("#franchiseform").submit(); 
    } 

的結合:

jQuery("input.preview").bind("click", changeForm); 

形式:

<form method="post" enctype="multipart/form-data" action="franchiseinsert.php" class="insert-new" id="franchiseform"> 

的按鈕:

<input type="button" value="Preview" id="preview" name="preview" id="preview" class="preview" /><input type="submit" value="Insert" /> 
+3

那麼最新的問題? – 2010-01-20 18:04:31

+0

說真的,問題在哪裏? – 2010-01-20 18:37:42

+0

說真的,我編輯了這個問題。問題在於它不能按預期工作,對於混淆感到抱歉。 – 2010-01-20 19:00:47

回答

0

事實證明,這是一個Firefox/Mac的特定錯誤。它適用於其他平臺和瀏覽器,但出於某種原因不適用於此特定計算機。這可能是一個擴展衝突或別的什麼,我只是使用另一個瀏覽器。

+0

只要知道,如果這個網頁被用於公共使用,那麼你正在疏遠一個體面的用戶份額。 – ryanulit 2010-01-26 19:25:50

0

除非你剝離得太多,看起來你需要把你的「after」調用放到一個名爲「changeForm」的函數中,這是你綁定到click事件的東西。

否則,保留鏈接:

jQuery("input.preview").bind("click", function(){ 
    jQuery("#franchiseform").attr("action", "franchisepreview.php")); 
    jQuery("#franchiseform").submit(); 
}); 
+0

不,它是一個函數。我編輯了原始問題。 – 2010-01-20 18:29:31

+0

好吧,更改綁定方法以調用Jquery(「#preview」) – Cryophallion 2010-01-20 18:33:21

+0

並且是僅用於測試的警報?我會使用螢火蟲或類似的東西,看看點擊是否改變了事情,只是在功能上保持動作的改變,以確保它正在發射。 – Cryophallion 2010-01-20 18:35:09

1

首先,你需要清理

<input type="button" value="Preview" id="preview" name="preview" id="preview" class="preview" /> 

到:

<input type="button" value="Preview" id="preview" name="preview" /> 

爲輸入不應該有多個ID屬性你不應該使用同名的類和id。這可能是你遇到問題的原因之一。然後我用下面的代碼和操作URL實際上改變:

<html> 
<head> 
    <title></title> 

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> 

    <script type="text/javascript"> 
     $(document).ready(function() { 

      $("#preview").bind("click", changeForm); 

      function changeForm(event){ 
       alert("Before: "+ $("#franchiseform").attr("action")); 
       $("#franchiseform").attr("action", "franchisepreview.php"); 
       alert("After: "+ $("#franchiseform").attr("action")); 
       $("#franchiseform").submit(); 
      } 
     }); 
    </script> 

</head> 
<body> 
    <form method="post" enctype="multipart/form-data" action="franchiseinsert.php" class="insert-new" id="franchiseform"> 
     <input type="button" value="Preview" id="preview" name="preview" /> 
     <input type="submit" value="Insert" /> 
    </form> 
</body> 
</html>