现在的代码是在这样的
$container.children().last().find('.time').html(data[i].pTime);
$container.children().last().find('.textcon').html(data[i].pText);
if(data[i].pState !== '健康'){
$container.children().last().find('.dot').addClass('error-dot');
$container.children().last().find('.triangle').addClass('error-triangle');
$container.children().last().find('.textcon').addClass('error-textcon');
}`
有没有更加简便的写法啊?
同时find多个p,然后设置html或者添加class,我试了下用逗号隔开不行,求指导~。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
不知道你是怎么用逗号隔开的。
然后给你个建议。
这里
$container.children().last()重复写了很多次,这样是很消耗性能,你应该用变量先缓存下来。然后后续只需引用该变量即可,这样写的代码都少了。
不会装个简单的函数吗?
你为什么不在这几个上面添加同一个class