获取当前div中的文本(只获取当前div的, 子元素不要, 基于layui)

<!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>
上一篇:c++ (模板 && 类模板)


下一篇:MySQL手注之root权限的处理