2012-06-28 77 views
0

我知道這個問題是相當基本的,但我是JQuery的新手,無法鍛鍊解決方案。當點擊cloase圖像時,獲取jquery中的複選框值

當點擊一個圖像的cloase按鈕,即'x'按鈕時,我想從模式窗口中獲取複選框的值。

任何幫助表示讚賞。謝謝..

我加$後,下面的代碼(文件)。就緒(函數(),

$('img#closeImg').on('click', function(){ 
alert($('.popupContact input[type=checkbox]').val()); 

下面是HTML代碼

<div id="popupScreen"> 
    <div id="popupContact"> 
    <form name="ReportParametersForm" name="ProcessActionForm" action="<portlet:actionURL> 
      <portlet:param name='generateReportAction' value='generateReportAction'/> 
      </portlet:actionURL>" method="post" onSubmit="return sendUserFeedback(doNotAsk)"> 
     <img src="<%= renderRequest.getContextPath() %>/NavigationClose.gif" id="closeImg" align="right" onclick="disablePopup()"> 
     <br/> 
     <p id="contactArea"> 
      To help us improve our intranet pages, can you please tell us in about 12 words, what you are accessing this area of the intranet for? 
      <br/><br/> 

      <table> 
      <tr> 
      <td><input type="text" name="userInput" id="userInput" size="60" onfocus="this.value='';" value="I am trying to find..."/></td> 
      <td><input type="submit" name="submitFeedback" value="Send feedback"> </td> 
      </tr> 
      </table> 
      <br/><input type="checkbox" name="doNotAsk" class=""> Please do not ask me for this feedback again 
      </form> 
    </div> 
    <div id="thankYou"> 
    <img src="<%= renderRequest.getContextPath() %>/NavigationClose.gif" align="right" onclick="disableNow()"> 
    <form name="closingForm" name="closingForm"> 
      <h5>Thank you for providing feedback to help us improve Exchange</h5> 
      <br/> 
      <br/> 
      <input type="button" name="Close" value="Close" onClick="disableNow()"> 
      </form> 
    </div> 
    <div id="backgroundPopup"></div> 
    <div id="mask"></div> 
    </div> 

回答

1
$('img#x').on('click', function(){ 
    alert($('.modal input[type=checkbox]').first().val()); 
}); 
  • 附加一筆事件映射到ID爲x的圖片元素
  • 點擊後,處理程序會提醒第一個名爲modal的類的HTML片段中的複選框的值。
+0

嗨Xander感謝您的快速回復......但如果我使用上面的代碼它甚至不loa模態窗口...任何想法爲什麼它這樣做,怎麼辦? – user1127172

+0

hello @ user1127172,我不知道沒有提供整個repro的問題... – xandercoded

+0

我正在加載這個模式窗口onload的頁面...所以當我把上面的代碼只是在$(document).ready (函數()它停止加載模態窗口..是否有意義? – user1127172

相關問題