gpt4 book ai didi

jquery - 从 h1 中查找文本并用它替换 foo2 文本

转载 作者:行者123 更新时间:2023-12-03 22:34:41 27 4
gpt4 key购买 nike

我正在尝试使用 jQuery 查找 H1 中的文本,然后使用它替换 foo2 中已有的文本。示例如下:

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Take text from element</title>
<script type="text/javascript">
var str = $("h1").text();
$("#foo2").html(str);
$("#foo2").replaceWith( str );
</script>
</head>

<body>

<div id="foo"><div id="foo2">replace with h1</div></div>

<h1>Text I want to take</h1>

</body>
</html>

最佳答案

$("#foo2").text($("h1").text());

关于jquery - 从 h1 中查找文本并用它替换 foo2 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13932762/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com