9***@qq.com
9***@qq.com
  • 发布:2018-09-03 14:24
  • 更新:2018-09-03 20:01
  • 阅读:6512

mui获取id选择器

分类:MUI

--switch开关
<div class="mui-switch mui-switch-blue" id="switch1">
<div class="mui-switch-handle" ></div>
</div>
<button type="button" onclick="getSwitchValue();">获取开关的状态</button>

js中:
function getSwitchValue(){
// var objSw=mui("#switch1");
var objSw=document.getElementById("switch1");
var isActive=objSw.classList.contains("mui-active");
if(isActive){
mui.toast("开关打开")
}else{
mui.toast("开关关闭");
}
}
问题:为啥var objSw=mui("#switch1"); 这些获取id选择器就不作用,但是通过document.getElementById("switch1");就可以呢??mui这个和document那个有啥区别??求大佬分析

2018-09-03 14:24 负责人:无 分享
已邀请:
DCloud_UNI_CHB

DCloud_UNI_CHB

mui使用css选择器获取HTML元素,返回mui对象数组。

因此你的代码应修改为:

var objSw=mui("#switch1")[0]
  • 9***@qq.com (作者)

    嗯呢,谢谢大佬

    2018-09-04 09:23

该问题目前已经被锁定, 无法添加新回复