如何在切换翻转开关后显示弹出屏幕?

How do I make a popup screen to appear once I toggle a flipswitch?

我正在使用 jQuery 移动设备创建学校项目。

我希望有一个分配了 Yes/No 的切换按钮,当切换该选项时,我希望出现一个相应的弹出窗口以确认更改。

执行此操作的最佳方法是什么,因为我已经尝试了几种变体但没有成功。谢谢!

<!--jQuery CDN Hosted Files-->
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
    <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

    <form id="flipswitchTeacher">
            <label for="flipswitch">Are you available to teach?</label>
            <select name="flipswitch" id="flipswitch" data-role="flipswitch" data-corners="false">
                <option a href="#confirmTeacherNo" value="no">NO</option>
                <option a href="#confirmTeacherYes" value="yes">YES</option>
            </select>
        </form>


        <div data-role="popup" id="confirmTeacherNo" class="ui-content" data-theme="a">
        <p>Confirm No</p>
        </div>

        <div data-role="popup" id="confirmTeacherYes" class="ui-content" data-theme="a">
        <p>Confirm Yes</p>
        </div>

如果您查看此处找到的详细信息:https://api.jquerymobile.com/popup/,您将看到:

Using the markup-based configuration, when a link with the data-rel="popup" is tapped, the corresponding popup container with the id referenced in the href of the link will be shown. To open a popup programmatically, call popup with the open method on the popup container:

$( "#myPopupDiv" ).popup( "open" )

可以这样执行:

$(function() {
  $("#flipswitch").change(function(e) {
    var target = $("option:selected", this).attr("href");
    $(target).popup("open");
  });
});
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

<form id="flipswitchTeacher">
  <label for="flipswitch">Are you available to teach?</label>
  <select name="flipswitch" id="flipswitch" data-role="flipswitch" data-corners="false">
    <option href="#confirmTeacherNo" value="no">NO</option>
    <option href="#confirmTeacherYes" value="yes">YES</option>
  </select>
</form>


<div data-role="popup" id="confirmTeacherNo" class="ui-content" data-theme="a">
  <p>Confirm No</p>
</div>

<div data-role="popup" id="confirmTeacherYes" class="ui-content" data-theme="a">
  <p>Confirm Yes</p>
</div>

希望对您有所帮助。