我们可以使用jQuery通过load函数获取属性值吗?
$(#id).load('url of page #source id').attr();
最佳答案
我真的不明白你在寻找什么,希望这有帮助,:D
您想在 div new-projects
中添加 ul,并且需要获取 ul
元素的属性。您可以执行以下操作
假设 HTML 是这样的
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>load demo</title>
<style>
body {
font-size: 12px;
font-family: Arial;
}
</style>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
</head>
<body>
<b>Projects:</b>
<div id="new-projects"></div>
<script>
$( "#new-projects" ).load("/load.html #projects ul", function(data){
var x = data;
$(x).find('ul').attr('style'); //console.log or alert this
} );
</script>
</body>
</html>
加载.html
<html>
<body>
<div id="projects">
<ul style="color:blue">
<li>Test</li>
<li> This</li>
</ul>
</div>
</body>
</html>
关于jquery - 有没有任何方法可以使用 jQuery 从另一个 html 文件获取属性值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59349621/