jquery 遍历dom节点

jquery 遍历dom节点

实例

$('#answer_' + id).find('li.answer-list').each(function (i, li) {
                        var $li = $(li);
                        var $div = $li.find('>div');
                        var $answerDiv = $div.find('>div');
                        var answerContent = $answerDiv.html();
                        var limit = 300;//字符限制
                        if (answerContent && answerContent.length > limit) {
                            com.whuang.hsj.setCustomAttr($answerDiv.get(0), 'originalVal', answerContent);
                            answerContent = omitTooLongString(answerContent, limit, true);
                            $answerDiv.html(answerContent);
                            console.warn('超长');
                            $div.find('ul.operate-list').append('<li> <a href="javascript:showAllAnswer(\'' + $answerDiv.attr('id') + '\')">显示全部</a> </li>');
                        }
                        // console.log(answerContent)
                    })

相关推荐