버튼을 누른 후에 만 ​​jQuery 쇼에서 대화 상자를 만드는 방법은 무엇입니까?

StackOverflow https://stackoverflow.com/questions/1413147

  •  06-07-2019
  •  | 
  •  

문제

이 코드는 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 -->

누구든지 버튼을 누른 후에만이 쇼를 만드는 방법을 말해 줄 수 있습니까? 지금은로드 직후 페이지에 자동으로 표시됩니다.

도움이 되었습니까?

해결책

옳고 그름, 다음은 내가 사용하는 일반적인 경고 스타일 대화 상자의 예입니다.

대화 상자 설정 (문서 준비) :

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

대화 상자를 엽니 다 (일부 이벤트 후) :

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

다른 팁

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

<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"/>
$("#btnTest").click(function() {
       $('#dialog').dialog('open');
        return false;
    })

정의 한 대화 상자를 열어야합니다 - 대화 상자 열기 기능을 첨부하여 버튼의 이벤트를 클릭하십시오.

오 - 그리고 세트 autoOpen: false 대화 속성에서 :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top