原本的在html元素内调用方法传this可替换为jq选择器选择对应样式,然后设置监听事件:
投诉建议单选
/* function checkThis(e){
var allSpan = document.getElementsByTagName("span");
for (var int = 1, length = allSpan.length; int < length; int++) {
allSpan[int].className = "pay_list_c1";
}
var theSpan = e.getElementsByTagName("span")[0];
theSpan.className = "pay_list_c1 on";
var myInput = theSpan.getElementsByTagName("input")[0];
myInput.checked = true;
} */
var btn = $(".col-xs-2.label98"); //获取单选btn元素
for (var i = 0, length = btn.length; i < length; i++) { //把每个button元素便利出来
var button = btn[i];
if (button.addEventListener) { //判断游览器的兼容问题,如果是ie8以下的用的是else语用代码段里的
button.addEventListener("click", change)
} else {
button.attachEvent("onclick", change)
}
}
function change(e) { //e.currentTarget触发该事件的元素 e.target则是目标节点元素
var allSpan = document.getElementsByTagName("span");
for (var int = 1,length = allSpan.length; int < length; int++) {
allSpan[int].className = "pay_list_c1";
}
e.currentTarget.getElementsByTagName("span")[0].className = "pay_list_c1 on";
e.target.checked = true;
}
信用评价星星
/* function eva(e){
var star = e.parentNode.getElementsByTagName("span");
for (var int = 0,length = star.length; int < length; int++) {
if(int<e.title){
star[int].className = "pj-star-icon on";
}else{
star[int].className = "pj-star-icon";
}
}
e.parentNode.getElementsByTagName("input")[0].value = e.title;
} */
var btn = $(".pj-star-icon"); //获取单选btn元素
for (var i = 0, length = btn.length; i < length; i++) { //把每个button元素便利出来
var button = btn[i];
if (button.addEventListener) { //判断游览器的兼容问题,如果是ie8以下的用的是else语用代码段里的
button.addEventListener("click", change)
} else {
button.attachEvent("onclick", change)
}
}
function change(e) { //e.currentTarget触发该事件的元素 e.target则是目标节点元素
var thisElem = e.currentTarget; //由于span内部没有其他东西,这里的e.currentTarget==e.target
var star = thisElem.parentNode.getElementsByTagName("span");
for (var int = 0, length = star.length; int < length; int++) {
if (int < thisElem.title) {
star[int].className = "pj-star-icon on";
} else {
star[int].className = "pj-star-icon";
}
}
thisElem.parentNode.getElementsByTagName("input")[0].value = thisElem.title;
}