<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>test2</title> <link rel="stylesheet" type="text/css" href="res/layui/css/layui.css"> <script type="text/javascript" src="res/layui/layui.js"></script> </head> <body> <div id="test-box"> aaaaa <div> bbbbb </div> </div> <script type="text/javascript"> layui.use(["layer"],function() { var layer = layui.layer; var $ = layui.jquery; var str = $('#test-box').contents().filter(function (index, content) { console.log(index); console.log(content); return content.nodeType === 3; }).text(); // alert($("#test-box").text()); alert(str); }); </script> </body> </html>