gpt4 book ai didi

javascript - jQuery 非常简单的代码似乎不起作用

转载 作者:行者123 更新时间:2023-12-02 16:21:04 25 4
gpt4 key购买 nike

这是我的 jQuery 代码:

(function() {


var overlay = {

init: function() {

$('<div></div>', {
class: 'overlay'
})
.insertAfter('button');

}

};

overlay.init();

})();

我希望这会在我的按钮下放置一个 div,但是创建的 HTML 不包含 div:

  <body>

<button>Reveal More Info</button>

</body>

抱歉,如果这是一个新手问题,我刚刚开始学习。

HTML 头部:

<head>
<title>jQuery rules</title>

<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="script.js"></script>
<style>

body {
background: yellow;
}

button {
margin: 100px 0 0 200px;
}

div {
display: none;
width: 600px;
height: 400px;
background-color: white;
border-radius: 40px;
position: absolute;
left: 25%;
top: 30%;
}

</style>

</head>

最佳答案

从 jQuery 文档中,请参阅 http://api.jquery.com/jQuery/#jQuery-html-attributes :

Blockquote The name "class" must be quoted in the object since it is a JavaScript reserved word, and "className" cannot be used since it refers to the DOM property, not the attribute.

关于javascript - jQuery 非常简单的代码似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29109400/

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