gpt4 book ai didi

javascript - const ddk = document.querySelector ('#ddk > input' );不起作用?只在控制台中显示 null

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

我正在尝试制作一个货币转换器,但 querySelector 为空,我不知道如何修复它。

HTML:

<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="valuta.js"></script>
<link rel="stylesheet" type="text/css" href="valuta.css">
</head>
<body>
<div class="ddk">
<input type="number" placeholder="DDK">
</div>

<div id="usd">
<input type="number" placeholder="DDK">
</div>

<div id="eur">
<input type="number" placeholder="DDK">
</div>

</body>
</html>

JS:

const ddk = document.querySelector('#ddk > input');
const usd = document.querySelector('#usd > input');
const eur = document.querySelector('#eur > input');

console.log(ddk);

最佳答案

const ddk = document.querySelector('.ddk > input');

# 匹配 id,. 匹配类。

const ddk = document.querySelector('.ddk > input');
console.log(ddk);
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="valuta.js"></script>
<link rel="stylesheet" type="text/css" href="valuta.css">
</head>
<body>
<div class="ddk">
<input type="number" placeholder="DDK">
</div>

<div id="usd">
<input type="number" placeholder="DDK">
</div>

<div id="eur">
<input type="number" placeholder="DDK">
</div>

</body>
</html>

关于javascript - const ddk = document.querySelector ('#ddk > input' );不起作用?只在控制台中显示 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55195179/

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