2016-08-26 4 views
0

버튼 클릭시 jquery 대화 상자를 열려고합니다. 하나의 버튼으로 하나의 대화 상자가 제대로 작동하는 것이 문제이지만 대화 상자와 버튼 쌍을 동적으로 생성했습니다. jquery 각 함수를 대화 상자를 초기화하는 데 사용하고 있지만 작동하지 않습니다.jquery 대화 상자 클래스 선택기 각 함수

내 PHP는 코드

echo '<div class="cp-button"> 
    <div class="popup" title="something"> $row[1] </div> 
    <input type="button" value="Show Code" class="btnGetCode"/>'; 
echo '</div>'; 

JQuery와

$(".popup").each(function() { 
    $(this).dialog(
    { 
     autoOpen: false, 
     width: 880, 
     height: 270, 
     show: { 
      effect: "blind", 
      duration: 1000 
     }, 
     hide: { 
      effect: "explode", 
      duration: 1000 
     } 
    }); 
}); 

$(".btnGetCode").on("click", function() { 
    $(this).prev().dialog("open"); 
}); 

답변

0

$(function(){ 
    $(".cp-button").on("click", ".btnGetCode", function(){ 
    //code 
    }); 
}); 

편집을 시도해보십시오 당신은 눈에 보이는 요소가해야 할 때 페이지로드 https://jsfiddle.net/orlandordzch/j7xfyL93/1/

+0

의 – Muniba

+0

내 scenarion에 따라 바이올린을 구현할 수 없습니다 예 –

+0

와 지금 시도 작동하지, 나는 오전 jquery에서 초급. 어쨌든 고마워, 대답 해. – Muniba

0

그것을 알아 냈 :

HTML

echo '<div class="cp-button"> 
    <div class="popup" for="tag'.$i.'"> somehing </div> 
    <input type="button" value="Show Code" class="btnGetCode" id="tag'.$i.'"/> </div>'; 

를 JQuery와

var opt={  
      autoOpen: false, 
      width: 880, 
      height: 270, 
      show: { 
       effect: "blind", 
       duration: 1000 
      }  
     }; 

$(".popup").dialog(opt); 
$(".btnGetCode").click(function() { 
    $(".popup[for='"+this.id+"']").dialog("open"); 
    return false;  
});