问题描述:
在开发过程中,遇到了自定义单选按钮组。因为使用了,aui.css的框架,导致了网上通常的通过<lable><input></input></lable>隐藏input中默认按钮的形式在本应用中不起作用,切app的开发图标通常使用的是字体图标。为了解决相关的问题,应使用js动态来处理相关的问题。
解决代码:
html:
<div class="dl aui-list-item-inner aui-list-item-right aui-padded-r-0">
<div class="aui-list-item-right right">
<span class="iconfont icon-icon icon-add-info aui-font-size-20" style="color:#868686"></span>
</div>
<div class="aui-list-item-right wrong">
<span class="iconfont icon-icon1 icon-add-info aui-font-size-20" style="color:#868686"></span>
</div>
</div>
javaScript
需要引用jQ
var RightArray = new Array();
RightArray = document.getElementsByClassName('right');
var WrongArray = new Array();
WrongArray = document.getElementsByClassName('wrong');
for (var i = 0; i != RightArray.length; i++) {
RightArray[i].onclick = function() {
$(this).children().attr('style', 'color:#46C11B');
$(this).parent().children().eq(1).children().attr('style', 'color:#868686');
// if ($(this).children().eq(0).children().eq(1).children().eq(0).attr("style") == "color:#46C11B") {
// $(this).children().eq(0).children().eq(1).children().eq(0).attr('style', 'color:#868686');
// } else {
// $(this).children().eq(0).children().eq(1).children().eq(0).attr('style', 'color:#46C11B');
// }
}
}
for (var i = 0; i != RightArray.length; i++) {
WrongArray[i].onclick = function() {
$(this).children().attr('style', 'color:#F5862D');
$(this).parent().children().eq(0).children().attr('style', 'color:#868686');
// if ($(this).children().eq(0).children().eq(1).children().eq(0).attr("style") == "color:#46C11B") {
// $(this).children().eq(0).children().eq(1).children().eq(0).attr('style', 'color:#868686');
// } else {
// $(this).children().eq(0).children().eq(1).children().eq(0).attr('style', 'color:#46C11B');
// }
}
}
此处,使用了attr是因为在本程序中,行内的代码才能显示出来;