2017-02-13 50 views
0

我一直在一个项目中,我有两个选择在html代码。jquery不能与物化选择隐藏

第二个选择应该只在第一个选择满足某些条件时启用。

这里是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代码会很酷。 :)

+0

我想在你的jsfiddle中,你错过了关闭brac'});'在最后。 –

+0

@AururRahmanMunna真棒抓人。我多愚蠢。 – unlucy7735

回答

0

我从here.

感谢答案@ahrim。

问题是物化html元素的方式。为了做任何更新,

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