【问题标题】:jquery is not working along with Materialize for select option hidingjquery 不能与 Materialize 一起用于选择选项隐藏
【发布时间】:2017-02-13 05:29:53
【问题描述】:

我一直在做一个项目,其中我在 html 代码中有两个选择。

只有当第一个选择满足某些条件时,才应该启用第二个选择。

这里是JSfiddle 链接。

$(document).ready(function() {
      $('select').material_select();
      $("select[name=type]").change(function() {
        alert("hola");
        if (this.value == "1") {
          <!-- $("select[name=Effect]").material_select("destroy"); -->
          $("select[name=Effect]").prop("disabled", false);
          <!-- $("select[name=Effect]").material_select(); -->
        } else {
          <!-- $("select[name=Effect]").material_select("destroy"); -->
          $("select[name=Effect]").prop("disabled", true);
          <!-- $("select[name=Effect]").material_select(); -->
        }

      });
<div class="input-field col sm2">
  <select name="type">
    <option value="" disabled selected>Choose your option</option>
    <option value="1">A</option>
    <option value="2">B</option>
    <option value="3">C</option>
  </select>
  <label>Type</label>
</div>

<div class="input-field col sm2">
  <select name="Effect" disabled>
    <option value="" disabled selected>Choose your option</option>
    <option value="1">AA</option>
    <option value="2">BB</option>
    <option value="3">CC</option>
  </select>
  <label>Effect</label>
</div>

注意: 没有具体化的 Jquery 运行良好。

任何形式的帮助都可以。

Jsfiddle 代码会很酷。 :)

【问题讨论】:

  • 我认为在你的 jsfiddle 中你错过了最后关闭 brac });
  • @AtaurRahmanMunna 很棒的抓人。我多么愚蠢。

标签: javascript jquery css html-select materialize


【解决方案1】:

我从here.得到了答案

感谢@ahrim。

问题是物化在 html 元素上工作的方式。为了进行任何更新,

  1. 您必须销毁Mr.Materialize$('#mySelectID').material_select('destroy');
  2. 使用 jquery(或任何 JS)完成您的工作
  3. 重新附加Mr.Materialize。 - $('#mySelectID').material_select();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-13
    • 2011-07-16
    • 1970-01-01
    • 1970-01-01
    • 2014-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多