我正在尝试制作货币转换器,但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);
答案 0 :(得分:1)
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>