永发信息网

JQuery获取div内的值,并根据值做出相应判断【十万火急】

答案:3  悬赏:30  手机版
解决时间 2021-02-13 23:19
  • 提问者网友:戎马万世
  • 2021-02-13 13:06
JQuery获取div内的值,并根据值做出相应判断【十万火急】
最佳答案
  • 五星知识达人网友:行路难
  • 2021-02-13 14:42
追问有多个li,不需要弹出,只需要修改div内的文本或者修改样式。我这不能传代码。网络监察部门会查追答
    既然有li,那么就有ul 在ul上加id,这里是kk
全部回答
  • 1楼网友:独钓一江月
  • 2021-02-13 17:11




无标题文档





 
     全部
        用户
        原创
        翻唱
    


$(function(){
    alert(getMsg("stop").num);
    alert(getMsg("stop").ins_status);    
    function getMsg(which){
        var $w = $("."+which),$n = $(".num",$w),$s = $(".ins_status",$w);
        return {"num":$n.text(),"ins_status":$s.text()};
    }
});
不知道你要哪个dd的值,写了个公用的,知道怎么用吧?
(1)调用getMsg,想要stop的,就传值stop给它。
(2)返回是个对象,两个属性,一个num、一个ins_status。追问

0</div>
instances</div>
</dd>
如果.instances .num的值为0,.instances加个class A 且将 .instance的文本改为xxx
如果.error .num的值为0,.instances加个class B追答$(function(){
    
    var ins = getMsg("instances"),
        error = getMsg("error");
    if(ins.num == "0"){
        var $ins = $("div.instances").addClass("A").text("xxx");
    }
    if(error.num == "0"){
        $ins.addClass("B");
    }
    
    function getMsg(which){
        var $w = $("."+which),
            $n = $(".num",$w),
            $s = $(".ins_status",$w),
            $i = $(".instances",$w),
            n = $n.length ? $n.text() : "",
            s = $s.length ? $s.text() : "",
            i = $i.lenght ? $i.text() : "";
        return {"num":n,"ins_status":s,"instances":i};
    }
});
没调试过,你试试
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯