2011-09-29 6 views
0

내 페이지의 일부분 위에 작은 '화면'이 나타납니다. 이 화면에는 두 개의 버튼이 있습니다. 이 버튼 중 하나를 누르면 화면이 제거됩니다. 그러나 화면은 나중에 재사용해야하므로 항상 화면을 재구성하는 대신 페이지의 객체 데이터에 저장합니다. 저장된 화면을 다시로드하는 동안 두 번째로 화면이 나타나면 모든 이벤트가 사라진 것처럼 보입니다. 이 문제를 어떻게 해결할 수 있습니까?나는 내 이벤트를 잃어 버리지 만 어떻게 붙일 수 있을까?

function AddScreen() { 
    var store= $('#store'), screen; 
    if(objectStoringScreen.length > 0){ 
     screen = objectStoringScreen.data('screen'); 
    }else { 
     store = CreateStore(); //Create Store 
     $(this).parent().append(store); //Add Store 
     screen = Screen(); // Create Screen 
    } 

    PushScreen(screen); //Load selected screen 

    function Screen() { 
     //build div 
     // build two buttons and place them in the div 
     // btn1.click(onOK); btn2.click(onCancel); 
    } 

    function onOK() { 
     store.data('screen',screen); 
     PopScreen(); 
    } 
    function onCancel() { 
     PopScreen(); 
    } 
} 
+0

어떻게 이벤트 처리기를 연결합니까? '라이브 '를 사용하고 있습니까? –

+0

라이브는 없습니다. 그냥 .click – Zholen

+1

당신의 이벤트 처리기 중 하나를'.live ('click', function() ....')로 변경하고 그 것이 작동하는지 확인하십시오. –

답변

0

난 그냥 미리 화면을 만들고 필요할 때 토글합니다.

<div id="screen"> 
    Screen Div 
    <input type="button" value="OK" /> <input type="button" value="Cancel" /> 
</div> 
<div id="showScreen">click here to show the screen</div> 

    $(document).ready(function() { 
     // Screen already exists, just hide it. If you need to build it from data on the page, do it after it's hidden. 
     $('#screen').hide(); 

     // Some action that shows/hides your screen, I just used a click method as an example 
     $('#showScreen').click(function() { 
      if ($('#screen').css('display') == 'none') { 
       // Or you can build here if you need it to be updated in real time for whatever reason 
       // ex. $('#screen').append('<input type="button" id="someSpecialButton" value="Special Button" />'); 
       $('#screen').show(); 
      } 
      else { 
       $('#screen').hide(); 
      } 
     }); 

     // Screen button events, will still exist after hiding the screen 
     $('#screen input[type="button"]').click(function() { 
      alert('You clicked ' + $(this).attr('value') + ' on the screen'); 
     }); 
    }); 
관련 문제