2015-12-14 115 views
0
$(document).ready(function(){ 
var zone; //ZONE TO PASS THROUGH HTTP POST 
var NEcount; //COUNTER HOW MUCH NOT-EDITBALE ZONES USER MUST CONFIGURE 
NEcount = 5; //IF I NEED 20(ZONES = CELLS OF MAP) USER MUST CONFIGURE 25-20=5 NOT EDITABLE ZONE FOR EXAMPLE(I'LL TAKE THIS VALUE FROM HTML CONTENT AND CALCULATED WITH JSP/JAVA) 

    $('body div#presentation div#map a').click(function(){ 
     zone = $(this).attr('href'); 
     zone = zone.substr(5);//i generate html code with jsp/java function href is like ="#area1" 
    }); 

    $('body div#presentation div#map a p').click 
    (
     function() 
     { 
      if($(this).attr('class') === "white") 
      { 
       $.post("MSservlet", {postsend:"updateMap",attrib:"editable",elem:"0",cond:zone});//Servlet call a PreparedStatement Query that update editable field to 0 where zone field is equal to var zone 
        NEcount--; 
        $(this).attr('class','gray'); 
        if(NEcount <= 0) 
        { 
         $('#NEobb').html("HTML BUTTON THAT LINK TO END CONFIGURATION PAGE"); 

        } 
        else 
        $('#NEobb').text("count = "+NEcount); 
       } 
      else if($(this).attr('class') === "gray") 
       { 
       $.post("MSservlet", {postsend:"updateMap",attrib:"editable",elem:"1",cond:zone}); 
        NEcount++; 
        $(this).attr('class','white'); 
        if(NEconta <= 0) 
        { 
         $('#NEobb').html("HTML BUTTON IMHO"); //LINK TO END CONFIGURATION OF MAP        
        } 
        else 
        $('#NEobb').text("count = "+NEcount); 
       } 
     } 
); 

}); 

我對那些jQuery帖子有問題。jQuery:Post當我第一次和最後一次點擊時不起作用

我有一個來自comfiguration頁面的交互式地圖(簡單的)產品。 配置頁問我需要多少區域。與表單字段,通過該號碼,我傳遞給服務程序,web應用程序生成與地圖(具有一個Bean的矩陣表示)一個新的頁面,是這樣的:

(Map areas is like <a href="#areaNUMBERGENERATED"><p class="color"></p></a>) 

使用jQuery P個色彩變化通常但第一個帖子不起作用(第一次點擊) 因爲通過一個空白區域(我不知道爲什麼)。

併爲每個點擊後,第二我有這種情況(我是意大利人,很難解釋):

  • 我點擊區域1:先郵寄區= null來的servlet(DB拒絕更新) ,顏色變成從至灰白色

  • Reclicked AREA1:第二柱發送區= 1(更新工作在DB通常,顏色變爲白色再次)

  • 我再次點擊AREA1:第三後正常工作區= 1並將可編輯設置爲0在DB

  • 我點擊區域2:郵寄區= 1(通過前區(我相信))

  • 我點擊區域3:郵寄區= 2(這是問題)

  • 我再次點擊區域3:發送後區域= 2和正常更新應該是

  • 我再次點擊area3:post send zone = 2並正常更新應該是。

我該如何解決?請讓我知道爲什麼不工作。

感謝您的建議。

意大利學生。

更新後:

我有同樣的對象2種單擊功能。

所以當我點擊地圖區/區域時,帖子無法及時將var區(可能)。

或者

它的變種區集(我的英語不好對不起)

我沒有尚未解決之前,可以先執行職務。

對此提出建議?

+0

OMG。 當我點擊地圖區域時,我有2個事件一起觸發。使用.click()動作/函數的 。 所以郵政不能在時間區域(var區域尚未設置?) 當我編輯我的問題帖子時,我只是想出了爲什麼這不起作用。 –

+1

如果你想出來,你應該考慮張貼答案來幫助未來的訪問者。 –

+0

但我還沒有解決方案,等待專家的答案。 是的,我會的。 –

回答

0

無論如何感謝。

我剛剛編寫了一個工作解決方案。

說明: 我刪除second.click()動作塊(包含職位),因爲被perfomed之前設置了var區variable._

所以我搬到功能的if/else如果在塊首先.click()動作代碼。

在HTML中我具有N區域是這樣的:

<!--grigio = gray and bianco = white(italian translation) --> 
<div id="map"> 
<a href="#area1"><p class="grigio"></p></a> 
<a href="#area2"><p class="grigio"></p></a> 
<a href="#area3"><p class="grigio"></p></a> 
<a href="#area4"><p class="grigio"></p></a> 
<a href="#area5"><p class="grigio"></p></a> 
<br> 
<a href="#area6"><p class="grigio"></p></a> 
<a href="#area7"><p class="grigio"></p></a> 
<a href="#area8"><p class="grigio"></p></a> 
<a href="#area9"><p class="grigio"></p></a> 
<a href="#area10"><p class="grigio"></p></a> 
<br> 
<a href="#area11"><p class="grigio"></p></a> 
<a href="#area12"><p class="grigio"></p></a> 
<a href="#area13"><p class="grigio"></p></a> 
<a href="#area14"><p class="bianco"></p></a> 
<a href="#area15"><p class="bianco"></p></a> 
<br> 
<a href="#area16"><p class="bianco"></p></a> 
<a href="#area17"><p class="bianco"></p></a> 
<a href="#area18"><p class="bianco"></p></a> 
<a href="#area19"><p class="bianco"></p></a> 
<a href="#area20"><p class="bianco"></p></a> 
<br> 
<a href="#area21"><p class="bianco"></p></a> 
<a href="#area22"><p class="bianco"></p></a> 
<a href="#area23"><p class="bianco"></p></a> 
<a href="#area24"><p class="bianco"></p></a> 
<a href="#area25"><p class="bianco"></p></a> 
<br> 

</div> 

FOR選擇$(本)。兒童( 'P')被點擊的對象我使用的內部ATTR( '類')

$(document).ready(function(){ 
    var zone; //ZONA DA PASSARE ATTRAVERSO HTTP POST 
    var NEcount; //NON EDITABILI OBBLIGATORI DA INSERIRE 
    NEcount = 5; // INIZIALIZZARE CALCOLANDO LE NE DA INSERIRE SE 21 = 4; 

    $('body div#presentation div#map a').click(function(){ 
        zone = $(this).attr('href'); 
      zone = zone.substr(5); 

      if($(this).children('p').attr('class') === "white")//I added children for select p of the clicked object 
        { 
        $.post("MSservlet", {postsend:"updateMap",attrib:"editabile",elem:"0",cond:zone}); 
         NEcount--; 
         $(this).children('p').attr('class','gray');//I added .children('p') to select class attr and change color 
         if(NEcount <= 0) 
         { 
          $('#NEobb').html("HTML BOTTON THAT LINK TO THE END OF CONFIGURATION"); 

         } 
         else 
         $('#NEobb').text("counter = "+NEcount); 
        } 
       else if($(this).children('p').attr('class') === "gray")//Same read comments up 
        { 
        $.post("MSservlet", {postsend:"updateMap",attrib:"editabile",elem:"1",cond:zone}); 
         NEcount++; 
         $(this).children('p').attr('class','white'); 
         if(NEcount <= 0) 
         { 
          $('#NEobb').html("HTML BUTTON THAT LINK TO END OF CONFIGURATION JUST IN CASE COUNT IS EQUAL 0"); //bottone che reindirizza alla pagina di fine configurazione. 

         } 
         else 
         $('#NEobb').text("counter = "+NEcount); 
        } 

     }); 

}); 

我希望這有助於某人。 OMG。

相關問題