2014-01-15 4 views
0

두 개의 div에 대해 동일한 팝업 jquery를 사용하는 방법. 나는 팝업에 대한 jquery가 있고 그것은 div 팝업이고 다른 div에 대해 동일한 jquery를 사용하고 싶다. 도와주세요. 코드가 팝업에 대한두 div에 동일한 팝업 jquery를 사용하는 방법

<head> 
<script type="text/javascript" src="script1.js"></script> 
<script type="text/javascript" src="jquery.js"></script> 
<style> 
#backgroundPopup { 
z-index:1; 
position: fixed; 
display:none; 
height:100%; 
width:100%; 
background:#000000; 
top:0px; 
left:0px; 
} 
#toPopup { 
font-family: "lucida grande",tahoma,verdana,arial,sans-serif; 
background: none repeat scroll 0 0 #FFFFFF; 
border: 10px solid #ccc; 
border-radius: 3px 3px 3px 3px; 
color: #333333; 
display: none; 
font-size: 14px; 
left: 50%; 
margin-left: -402px; 
position: fixed; 
top: 20%; 
width: 800px; 
z-index: 2; 
} 
div.loader { 
background: url("../img/loading.gif") no-repeat scroll 0 0 transparent; 
height: 32px; 
width: 32px; 
display: none; 
z-index: 9999; 
top: 40%; 
left: 50%; 
position: absolute; 
margin-left: -10px; 
} 
div.close { 
background: url("../img/closebox.png") no-repeat scroll 0 0 transparent; 
cursor: pointer; 
height: 30px; 
position: absolute; 
right: -27px; 
top: -24px; 
width: 30px; 
} 
span.ecs_tooltip { 
background: none repeat scroll 0 0 #000000; 
border-radius: 2px 2px 2px 2px; 
color: #FFFFFF; 
display: none; 
font-size: 11px; 
height: 16px; 
opacity: 0.7; 
padding: 4px 3px 2px 5px; 
position: absolute; 
right: -62px; 
text-align: center; 
top: -51px; 
width: 93px; 
} 
span.arrow { 
border-left: 5px solid transparent; 
border-right: 5px solid transparent; 
border-top: 7px solid #000000; 
display: block; 
height: 1px; 
left: 40px; 
position: relative; 
top: 3px; 
width: 1px; 
} 
div#popup_content { 
margin: 4px 7px; 
/* remove this comment if you want scroll bar 
overflow-y:scroll; 
height:200px 
*/ 
}</style> 
</head> 
<body> 
<a href="#" class="topopup"><div id="ack" class="topopup">Location</div></a> 

<div id="toPopup"> 

    <div class="close"></div> 
    <span class="ecs_tooltip">Press Esc to close <span class="arrow"></span></span> 
    <div id="popup_content" width="400px" height="500px"> 

<input type="text" name="mm" id="id"> 
     <button id="ok">ok</button> 
    </div> <!--your content end--> 

</div> <!--toPopup end--> 

<div class="loader"></div> 
<div id="backgroundPopup"></div> 
</body> 

JQuery와 아래에 주어진다. 다른 div에 대해이 jquery를 사용하고 싶습니다. 하지만 난 다른 사업부에 같은 이름을 부여하지만 링크 클릭 이전 DIV에게

jQuery(function($) { 

$("a.topopup").click(function() { 
     loading(); // loading 
     setTimeout(function(){ // then show popup, deley in .5 second 
      loadPopup(); // function show popup 
     }, 500); // .5 second 
return false; 
}); 

/* event for close the popup */ 
$("div.close").hover(
       function() { 
        $('span.ecs_tooltip').show(); 
       }, 
       function() { 
        $('span.ecs_tooltip').hide(); 
       } 
      ); 

$("div.close").click(function() { 
    disablePopup(); // function close pop up 
}); 

$(this).keyup(function(event) { 
    if (event.which == 27) { // 27 is 'Ecs' in the keyboard 
     disablePopup(); // function close pop up 
    } 
}); 

    $("div#backgroundPopup").click(function() { 
    disablePopup(); // function close pop up 
}); 
$("button#ok").click(function() { 
    disablePopup(); 
}); 
$('a.livebox').click(function() { 
    alert('Hello World!'); 
return false; 
}); 

/************** start: functions. **************/ 
function loading() { 
    $("div.loader").show(); 
} 
function closeloading() { 
    $("div.loader").fadeOut('normal'); 
} 

var popupStatus = 0; // set value 

function loadPopup() { 
    if(popupStatus == 0) { // if value is 0, show popup 
     closeloading(); // fadeout loading 
     $("#toPopup").fadeIn(0500); // fadein popup div 
     $("#backgroundPopup").css("opacity", "0.7"); 
     $("#backgroundPopup").fadeIn(0001); 
     popupStatus = 1; // and set value to 1 
    } 
} 

function disablePopup() { 
    if(popupStatus == 1) { // if value is 1, close popup 
     $("#toPopup").fadeOut("normal"); 
     $("#backgroundPopup").fadeOut("normal"); 
     popupStatus = 0; // and set value to 0 
    } 
} 
/************** end: functions. **************/ 
    }); // jQuery End 

을 표시 할 때 나는 다른 DIV이 jQuery를 사용합니다. 하지만 다른 div에 동일한 이름이 부여되었지만 그 링크를 클릭하면 이전 div가 표시됩니다.

답변

0

<a class="topopup1"></a>을 사용한 적이 없습니까?

+0

그건 내 실수였다 유감과 함께. 나는 그 문제를 바로 잡았다. 실제 문제는 다른 div 또한이 jquery를 사용하고 싶습니다. 제발 도와주세요 ..... – user3189828

0

제안 사항은 <a>에 대상 속성을 추가하여 어떤 div가 팝업되는지 의미 할 수 있습니다. 예를 들어

:

HTML 코드

<a class="popup-button" target="#p1"></a> 
<a class="popup-button" target="#p2"></a> 
<div class="toPopup" id="p1">...</div> 
<div class="toPopup" id="p2">...</div> 

JS 코드

$(".popup-button").click(function{ 
    loading($(this).attr("target")); // loading 
    setTimeout(function(){ // then show popup, deley in .5 second 
     loadPopup($(this).attr("target")); // function show popup 
    }, 500); // .5 second 
}); 

function loading(selector) { 
    $(selector).show(); 
} 
function loadPopup(selector) { 
    if(popupStatus == 0) { // if value is 0, show popup 
     closeloading(); // fadeout loading 
     $(selector).fadeIn(0500); // fadein popup div 
     popupStatus = 1; // and set value to 1 
    } 
} 
0

를 사용하여 클래스 이름 앵커 태그

<a class='topopup1'>Show Popup</a> 
관련 문제