拨动拨动开关后,如何显示弹出屏幕?

时间:2018-11-11 17:22:18

标签: javascript jquery html jquery-mobile

我正在使用jQuery Mobile创建学校项目。

我正在寻找一个分配有“是/否”的切换按钮,当切换选项时,我希望出现一个相应的弹出窗口以确认更改。

执行此操作的最佳方法是什么,因为我尝试了几次变体而没有运气。谢谢!

<!--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>

1 个答案:

答案 0 :(得分:1)

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

  

使用基于标记的配置,当点击带有data-rel="popup"的链接时,将显示具有在链接的href中引用的ID的相应弹出容器。要以编程方式打开弹出窗口,请使用弹出容器上的open方法调用popup:

     

$( "#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>

希望有帮助。

相关问题