【问题标题】:material design disable dropdown using jQuery使用 jQuery 的材料设计禁用下拉菜单
【发布时间】:2018-05-06 04:59:20
【问题描述】:

如何在使用jQuery点击按钮时禁用材料设计dropdown

$("#btnoneway").click(function(){
  $(".airportToList").prop("disabled",true); 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select class="form-control airportToList"></select>

<a id="btnoneway">Click</a>

js:

$.each(a.airports, function (key, value) {
            $(".airportFromList").append($('<option></option>').val(value.code).html(value.city +' , '+ value.country +'  ('+value.code+')' ));
            $(".airportToList").append($('<option></option>').val(value.code).html(value.city +' , '+ value.country +'  ('+value.code+')' ));
        });

        $('.airportFromList').change(function () {
            //alert($(this).val());
            //Code to select image based on selected car id
        });

        $('.airportToList').change(function () {
            //alert($(this).val());
            //Code to select image based on selected car id
        });

上面的 jQuery 不工作。还有其他选择吗?

提前致谢

【问题讨论】:

  • 您的代码运行非常好 .. 尝试在其他地方找到它,例如console
  • @pedram 单击按钮时如何禁用下拉菜单??
  • 你已经有了!我说你的代码工作正常! |查看您的问题已更新。

标签: jquery material-design


【解决方案1】:

在这里检查过,这个正在工作。我给了“attr”而不是“prop”

$("#btnoneway").click(function(){
     $(".airportToList").attr("disabled","disabled"); 
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select class="form-control airportToList"> 
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<button id="btnoneway">click</button>

【讨论】:

  • 老兄,.attr("disabled","disabled"); .prop("disabled",true); 之间没有区别,而且 OP 代码工作正常,最好在收到 down vote 之前删除你的帖子
  • 是的,他仍然说他的代码不起作用,所以我要求他改变语法
  • 当然,问题出在其他问题上,而不是这种语法,因为代码在这里工作。
  • 其实我没有在这里传递
猜你喜欢
  • 2014-12-08
  • 2020-10-30
  • 1970-01-01
  • 2015-01-26
  • 2023-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多