2013-04-03 43 views
0

理念:使用jQuery來處理點擊()和調試的jQuery鉻

我在Struts2的java動態的形式,當用戶點擊「添加新的埃杜」鏈接,一個jQuery的功能將被解僱延長動態形式。這是我的jsp:

<html> 
<head> 
<script language="text/javascript" src="js/jquery-1.9.0.js"></script> 
<script language="text/javascript" src="js/common.js"></script> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Education List</title> 
</head> 
<body> 
<s:form action="/save" method="POST"> 
    <div class="educationForm"> 
     <c:if test="${ (not empty educations) }"> 
      <c:if test="${ fn:length(educations) ge 1 }"> 
       <c:forEach items="${educations}" var="edu" varStatus="status"> 
        <div class="educations">      
         <label>Position</label><input type="text" name="educations[${ status.index }].index" value="${ educations[status.index].index }" /><br/> 
         <label>School</label><input type="text" name="educations[${ status.index }].school" value="${ educations[status.index ].school }" /><br/> 
         <label>Degree</label><input type="text" name="educations[${ status.index }].degree" value="${ educations[status.index ].degree }" /><br/> 
         <label>GPA</label><input type="text" name="educations[${ status.index }].scored" value="${ educations[status.index ].scored }" /><br/> 
         <label>Start Date</label><input type="text" name="educations[${ status.index }].startDate" value="${ educations[status.index].startDate }" /><br/> 
         <label>End Date</label><input type="text" name="educations[${ status.index }].endDate" value="${ educations[status.index].endDate }" /><br/> 
        </div> 
       </c:forEach>   
      </c:if>   
     </c:if> 
     <div class="educations"> 
      <label>Position</label><input type="text" name="educations[${fn:length(educations)}].index" value="${fn:length(educations) + 1}" /><br/> 
      <label>School</label><input type="text" name="educations[${fn:length(educations)}].school" /><br/> 
      <label>Degree</label><input type="text" name="educations[${fn:length(educations)}].degree" /><br/> 
      <label>GPA</label><input type="text" name="educations[${fn:length(educations)}].scored" /><br/> 
      <label>Start Date</label><input type="text" name="educations[${fn:length(educations)}].startDate" /><br/> 
      <label>End Date</label><input type="text" name="educations[${fn:length(educations)}].endDate" /><br/> 
     </div> 
    </div> 
    <a href="#" id="addButton">Add new Edu</a> 
    <input type="submit" value="Save" />   
</s:form> 

<div class="template_educations" style="display:none"> 
    <div class="educations"> 
     <label>Position</label><input type="text" name="educations[_X_].index" /><br/> 
     <label>School</label><input type="text" name="educations[_X_].school" /><br/> 
     <label>Degree</label><input type="text" name="educations[_X_].degree" /><br/> 
     <label>GPA</label><input type="text" name="educations[_X_].scored" /><br/> 
     <label>Start Date</label><input type="text" name="educations[_X_].startDate" /><br/> 
     <label>End Date</label><input type="text" name="educations[_X_].endDate" /><br/> 
    </div> 
</div> 
</body> 
</html> 

Common.js文件:

$(document).ready(function(){ 
    $("#addButton").click(function(event){ 
     event.preventDefault(); 
     $(".educationForm").append($(".template_educations").html); 
     $(".educationForm").children(".educations").last().children("input").each(function(){   
      var count = $(".educationForm").children(".education").length(); 
      var value = $(this).attr("name"); 
      value.replace("_X_", count + 1); 
      $(this).attr("name", value); 
     });   
    }); 
}); 

問題:

  • 它看起來像jQuery的功能不能正常工作。我在Use jquery click to handle anchor onClick()嘗試了一些建議,但它沒有幫助。

  • 通常,我使用chrome來調試javascript。但在這種情況下,js文件不會出現在chrome開發工具的sources選項卡中,所以我無法在chrome中調試它。

對我的問題有任何建議嗎?

+0

第一次升級jquery到1.9.1有很多錯誤修復 –

+0

你試過在FF上使用Fire Bug嗎? – vynx

+0

@ArunPJohny我會嘗試你的建議,將盡快反饋 –

回答

1

您的腳本標記定義無效,語言屬性應具有值javascript而不是text/javascript>

<script language="javascript" src="js/jquery-1.9.0.js"></script> 
<script language="javascript" src="js/common.js"></script> 
+0

或者只是完全省略語言屬性。 –

+1

@甜菜根 - 甜菜根是 –

+0

它的工作原理。感謝您的幫助。現在我試圖將版本更改爲1.9.1以修復一些錯誤:D –