在写前端js的时候,需要对通过js追加的页面的标签进行控制。直接在js中写发现取不到 追加后的内容。 原来是页面加载的时候一直都找不到这个标签所以js不管用,通过在网上查看。发现了在某个事件触发的时候加载另外一个js。具体代码如下
//预选号js效果
$(document).ready(function(){
//查看和详情互相切换
$(".tab_tit li").unbind("click").bind("click",function(){
var rel = $(this).attr("data-rel");
$(".btn_bg").show(); //显示关闭按钮
if(!$(this).hasClass("up")){
$(this).html("详情");
$(this).addClass("up");
$(this).siblings().html("查看");
$(this).siblings().removeClass("up");
$(".tab_con").hide();
$(".tab_con").eq(rel).toggle();
}else{
$(".btn_bg").hide(); //隐藏关闭按钮
$(".tab_con").hide();
$(this).removeClass("up");
$(this).html("查看");
}
});
//关闭预选红球
$(".btn_bg").unbind("click").bind("click",function(){
$(".tab_con").hide();
$(".tab_tit li").html("查看");
$(".tab_tit li").removeClass("up");
$(this).hide();
});
//添加已选球和删除预选球
$("span").unbind("click").bind("click",function(){
if($(this).hasClass("btn_sp02")){
$(this).removeClass("btn_sp02");
if($(this).hasClass("btn_sp01")){
yx_var= $(this).html();
$(".tab_con_yx .btn_sp02").each(function(i,n){
var obj=$(n);
if(yx_var==obj.text()){
$(this).remove();
}
});
}
}else{
$(this).addClass("btn_sp02");
$(".tab_con_yx").append("<span class='btn_sp02' style='cursor:pointer' flag="+$(this).html()+">"+$(this).html()+"</span>");
//对已选红球进行排序
var ic = $(".tab_con_yx");
var spans = ic.find("span");
var arr = spans.get();
arr.sort(function(a, b) {
var ai = parseFloat($(a).attr("flag"));
var bi = parseFloat($(b).attr("flag"));
if (ai > bi) {
return 1;
} else if (ai < bi) {
return -1;
} else {
return 0;
}
});
ic.append(arr);
//对已选红球排序结束
$.getScript("ssqNew/js/ssq_hq_yltl.js", function() {
});
}
});
});