切换Material Design Lite复选框 [英] Toggle Material Design Lite checkbox

查看:113
本文介绍了切换Material Design Lite复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用材质设计精简版复选框,我正在尝试使用JavaScript检查或取消选中该元素。我试过这个:

I'm using a material design lite checkbox and I'm trying to check or uncheck the element using JavaScript. I tried this:

document.getElementById("checkbox-1").checked = true;

这不起作用。我用jQuery尝试了相同的方法:

That do not work. I tried the same approach with jQuery:

$("#checkbox-1").prop('checked',true); 

这也不起作用。任何帮助将不胜感激。

That did not work either. Any help would be appreciated.

推荐答案

目前,1.0.0中的此组件有一个错误,它不作为窗口小部件公开。这已得到修复。目前在大师和1.0.1补丁中,它将在稳定版本中供所有人使用。

Currently, this component in 1.0.0 has a bug where it is not exposed as a widget. This has been fixed. Currently in master and in a 1.0.1 patch in a few days, it will be available to everyone in a stable build.

这是处理它的正确方法如果您有修补版本将会工作:

This is the proper method to handle it that will work if you have a patched version:

检查元素:
document.querySelector('。mdl-js-checkbox ').MaterialCheckbox.check()

并取消选中:
document.querySelector('。 mdl-js-checkbox')。MaterialCheckbox.uncheck()

目前通过查看源代码并查看不以下划线结尾的属性。如果它们以下划线结尾,则它们仅供内部使用,不支持外部使用。

The full API can be discovered currently by looking at the Source code and viewing the properties that don't end in an underscore. If they end in an underscore, they are for internal use only and external use is not supported.

我们正在努力获取JS API的记录,但这需要一些更多时间完成并推出到网站。

We are working on getting the JS API's documented, but that will take some more time to finish and roll out to the site.

这篇关于切换Material Design Lite复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆