2016-10-02 49 views
0

我有一個表單的PHP文件。表單動作是另一個PHP文件。 當我提交表單時,下一頁(表單動作頁面)上的Jquery不起作用。但是當我自己打開那個頁面(而不是表單動作)時,Jquery工作得很完美。Jquery腳本不工作在頁面上表單發送到

守則第一頁上:

<!DOCTYPE html> 
<html> 
<head> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"> 
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script> 
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> 
<script src="getsnacks.js"></script> 
</head> 
<body> 

<div data-role="page"> 
    <div data-role="header" id="status"> 
     <h1>Snacks Bestellen</h1> 
    </div> 
    <div data-role="main" class="ui-content"> 

     <fieldset class="ui-field-contain" id="snack1"> 
      <span id="snack1optie1"> 
      <select name="optie1" id="optie1" class="optie1"> 
      </select> 
      </span> 
      <span id="snack1optie2"> 
      <select name="optie2" id="optie2" class="optie2"> 
      </select> 
      </span> 
      <span id="snack1optie3"> 
      <select name="optie3" id="optie3" class="optie3"> 
      </select> 
      </span> 
     </fieldset> 
    </div> 
</div> 

</body> 
</html> 

jQuery的頁面(只是一個測試)上:

$(document).ready(function() { 
    $('#snack1optie2').hide(); 
    $('#snack1optie3').hide();  
    $('#snack1optie1').click(function(){ 
     $('#snack1optie2').show(); 
    }); 
    $('#snack1optie2').click(function(){ 
     $('#snack1optie3').show(); 
    }); 
    $('#snack1optie3').click(function(){ 
     $('#snack1optie3').hide(); 
    }); 
}); 

由於在evaluatelogin.php頁面上

<!DOCTYPE html> 
<html> 
<head> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"> 
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script> 
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> 
<script src="login.js"></script> 
</head> 
<body> 

<div data-role="page"> 
    <div data-role="header" id="status"> 
     <h1>Snacks Bestellen</h1> 
    </div> 
    <div data-role="main" class="ui-content"> 
    <form method="post" action="evaluatelogin.php"> 
     <label for="company">Bedrijfsnummer:</label> 
     <input type="text" name="company" id="company"> 
     <fieldset class="ui-field-contain" id="fieldset_user"> 
     <label for="user">Gebruiker:</label> 
     <select name="user" id="user"> 
     </select> 
     </fieldset> 
     <input type="submit" value="Volgende" data-icon="user" data-iconpos="right" data-inline="true"> 
     </form> 
    </div> 
</div> 

</body> 
</html> 

代碼提前,

+0

你在哪裏把你的jQuery代碼? –

+0

它位於HEAD的getsnacks.js文件中。 –

+0

嘗試在$(document)以外編寫代碼.ready –

回答

0

表單提交使用AJAX進行。

提交時,jQuery Mobile將確保指定的Url能夠通過Ajax檢索並進行適當的處​​理。

將其與data-ajax="false"表單屬性關閉,它將正常工作。

<form method="post" action="evaluatelogin.php" data-ajax="false"> 

jQuery mobile docs

+0

太好了,謝謝你的工作! –

相關問題