2009-09-11 5 views
2

이 코드는 jQuery 사이트의 모달 확인 데모에서 가져온 것입니다.jQuery에서 단추를 누른 후에 만 ​​대화 상자를 만들 수 있습니까?

<script type="text/javascript"> 
$(function() { 
    $("#dialog").dialog({ 
     bgiframe: true, 
     resizable: false, 
     height:140, 
     modal: true, 
     overlay: { 
      backgroundColor: '#000', 
      opacity: 0.5 
     }, 
     buttons: { 
      'Yes': function() { 
       $(this).dialog('close'); 
      }, 
      'No': function() { 
       $(this).dialog('close'); 
      } 
     } 
    }); 
}); 
</script> 



<div class="demo"> 

<div id="dialog" title="Empty the recycle bin?"> 
    <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p> 
</div> 

<!-- Sample page content to illustrate the layering of the dialog --> 
<div class="hiddenInViewSource" style="padding:20px;"> 
    <p>Sed vel diam id libero <a href="http://example.com">rutrum convallis</a>. Donec aliquet leo vel magna. Phasellus rhoncus faucibus ante. Etiam bibendum, enim faucibus aliquet rhoncus, arcu felis ultricies neque, sit amet auctor elit eros a lectus.</p> 
    <form> 
     <input value="text input" /><br /> 
     <input type="checkbox" />checkbox<br /> 
     <input type="radio" />radio<br /> 
     <select> 
      <option>select</option> 
     </select><br /><br /> 
     <textarea>textarea</textarea><br /> 
    </form> 
</div><!-- End sample page content --> 

</div><!-- End demo --> 

<div class="demo-description"> 

<p>Confirm an action that may be destructive or important. Set the <code>modal</code> option to true, and specify primary and secondary user actions with the <code>buttons</code> option.</p> 

</div><!-- End demo-description --> 

버튼을 누른 후에 만이 쇼를 만드는 방법을 알려줄 사람이 있습니까? 지금은로드 직후 페이지에 자동으로 표시됩니다.

답변

0

일반적인 경고 스타일의 예는 다음과 같습니다. d (일부 이벤트 후) 대화

$("#generic-dialog").dialog({ 
    autoOpen: false, 
    buttons: { 
     Ok: function() { 
      $(this).dialog("close"); 
     } 
    } 
}); 

그리고 열 :

은 (문서 준비에서) 대화 상자를 설정 : 내가 사용하는 것이 ialog

$("#generic-dialog") 
    .text("Status updated successfully.") 
    .dialog("option", "title", "Your Status").dialog("open"); 
2

페이지에 단추를 추가하고 단추의 클릭 이벤트에 코드를 추가하십시오.

<script type="text/javascript"> 
$(function() { 
    $("#button").click(function(){ 
    $("#dialog").dialog({ 
      bgiframe: true, 
      resizable: false, 
      height:140, 
      modal: true, 
      overlay: { 
        backgroundColor: '#000', 
        opacity: 0.5 
      }, 
      buttons: { 
        'Yes': function() { 
          $(this).dialog('close'); 
        }, 
        'No': function() { 
          $(this).dialog('close'); 
        } 
      } 
     }); 
    }); 
    }); 
</script> 

및 HTML에

<input type='button' value="click" id="button"/> 
+0

을 나는 단순한 * 초 * 너무 느렸다 ... +1, 제 대답이 삭제되었습니다. –

1
$("#btnTest").click(function() { 
     $('#dialog').dialog('open'); 
     return false; 
    }) 
사용자가 정의한 대화 상자를 열어야합니다

는 -과에 autoOpen: false을 설정 - 버튼

오의 이벤트를 클릭하여 대화 상자가 열려있는 기능을 첨부 대화 상자 설정 등록 정보 :

관련 문제