简体   繁体   English

用于更改下拉选择并使用新选择重新加载小部件的按钮

[英]Button to change dropdown selection and reload widget with new selection

I have to incorporate a Healcode widget (through Mind Body) into the site I'm working on.我必须将 Healcode 小部件(通过 Mind Body)合并到我正在处理的站点中。 My goal is to have a button on that page change the dropdown selection of the Healcode widget and reload the widget to reflect the dropdown change.我的目标是让该页面上的按钮更改 Healcode 小部件的下拉选择并重新加载小部件以反映下拉更改。

So far I've been able to create a button that changes the dropdown selection to the desired value when clicked.到目前为止,我已经能够创建一个按钮,在单击时将下拉选择更改为所需的值。 However it does not reload the widget to reflect the change.但是,它不会重新加载小部件以反映更改。 I still have to manually click the dropdown to make that happen.我仍然必须手动单击下拉菜单才能实现。

Any help is appreciated!!任何帮助表示赞赏! Here's what I have so far:这是我到目前为止所拥有的:

HTML FOR THE HEALCODE DROPDOWN FILTERS:用于 HEALCODE 下拉过滤器的 HTML:

<div class="filters">
        <select name="mbo_class" id="mbo_class">
<option value="">All Classes</option><option value="58">200 hour Teacher Training</option>
<option value="3">Basics</option>
<option value="59">Basics/Power</option>
<option value="85">Basics/Restore + Meditation</option>
<option value="156">Cozy Winter YIN &amp; Restore</option>
<option value="23">Deep Stretch/YIN</option>
<option value="154">Express Power</option>
<option value="140">HIIT Power Yoga</option>
<option value="12">Music &amp; Power Yoga</option>
<option value="5">Power Yoga </option>
<option value="46">Power Yoga/Restore </option>
<option value="138">Simply Stretch</option>
<option value="30">Tween Yoga</option>
<option value="139">YOD (Yoga + HIIT)</option></select>
</div>

HTML & JS FOR BUTTON TO CHANGE THE SELECTION:用于更改选择的按钮的 HTML 和 JS:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#btn3").click(function(){
    $("#mbo_class").val("3");
  });
});
</script>
<button id="btn3">Set Value</button>

I'm thinking a working solution might be somehow capturing what the dropdown is changed to and then reloading the page, but my attempts have not worked thus far.我在想一个可行的解决方案可能会以某种方式捕获下拉列表更改的内容,然后重新加载页面,但到目前为止我的尝试还没有奏效。 Here's my latest attempt:这是我最近的尝试:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#btn3").click(function(){
    $("#mbo_class").val("3");
  });

  var selectedProduct = sessionStorage.getItem("product");
if(selectedProduct != undefined || selectedProduct != null){
    $("mbo_class").first().find(":selected").removeAttr("selected");
  $("mbo_class").find("option").each(function () {
            if ($(this).val() == selectedProduct) {
                $(this).attr("selected", true);
            }
        });
}

$('mbo_class').change(function () {
    sessionStorage.setItem("product", $("mbo_class").first().val());

  location.reload();
});
</script>
<button id="btn3">Set Value</button>

So I found a solution!所以我找到了解决方案! It isn't quite the direction I was planning to go, but it works!这不是我计划去的方向,但它有效! Since I can't actually change the HTML of the widget–the research I was doing led me to a lot of dead ends.由于我实际上无法更改小部件的 HTML - 我所做的研究使我陷入了很多死胡同。


In the HealCode widget app, I created a version of the schedule widget for each class type (the filter options mentioned above).在 HealCode 小部件应用程序中,我为每个班级类型(上面提到的过滤器选项)创建了一个时间表小部件版本。

Then I set the button to change the entire div id to display the correlated schedule widget.然后我设置按钮以更改整个 div id以显示相关的计划小部件。 (Rather than just filtering the current schedule widget.) (而不仅仅是过滤当前计划小部件。)

We'll use the example of filtering for the "Basics Class".我们将使用过滤“基础类”的示例。

Here's my HTML code:这是我的 HTML 代码:

<div id="widget-container">
  <healcode-widget data-type="schedules" data-widget-partner="object" data-widget-id="3c106917a43" data-widget-version="0">
</healcode-widget>

<a id="schedule-basics" class="button">Basics schedule</a>

Here's the script–which changes the schedule displayed to the "Basics Class" schedule (much like the filter selection would):这是脚本 - 它将显示的时间表更改为“基础课程”时间表(很像过滤器选择):

 $(document).ready(function() {
    var scheduleWidgetMarkup = '<healcode-widget data-type="schedules" data-widget-partner="object" data-widget-id="3c1218147a43" data-widget-version="1" ></healcode-widget>';
    $('body').on('click', '#schedule-basics', function(e) {
      e.preventDefault();
      $('#widget-container').html(scheduleWidgetMarkup);
    });
  });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM