gpt4 book ai didi

javascript - jQuery 不会返回预期的 .text 值

转载 作者:行者123 更新时间:2023-11-28 11:37:55 27 4
gpt4 key购买 nike

我是 jQuery 新手,我有一个包含此 div 元素的 html 文件。

<div id="test div">Test Text</div>

还有这个 div 元素。

<div id="dump contents"></div>

在我的 javascript 文件中,我有这个:

var testvariable = $("#test div").text();
$("#dump contents").html(testvariable);

但无论我做什么,都没有发生:(

有什么建议吗?提前致谢!

最佳答案

id 属性不应包含空格

<div id="test-div">Test Text</div>

<div id="dump-contents"></div>

JavaScript:

var testvariable = $("#test-div").text();
$("#dump-contents").html(testvariable);

来自w3.org

The id attribute specifies its element's unique identifier (ID). The value must be unique amongst all the IDs in the element's home subtree and must contain at least one character. The value must not contain any space characters.

关于javascript - jQuery 不会返回预期的 .text 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14130253/

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