<h1>黄瓜3.5元/斤 西红柿2.7元/斤  计算2斤黄瓜3斤西红柿总价</h1>
<p>本页面提供黄瓜和西红柿的单价,并计算2斤黄瓜3斤西红柿的总价。</p>
<p>黄瓜价格: <span>3.5</span> 元/斤</p>
<p>西红柿价格: <span>2.7</span> 元/斤</p>
<p>2斤黄瓜3斤西红柿的总价: <span id='total'></span> 元</p>
<script>
const cucumber = document.querySelector('span:nth-of-type(1)');
const tomato = document.querySelector('span:nth-of-type(2)');
const total = document.querySelector('span:nth-of-type(3)');
<p>const cucumberPrice = parseFloat(cucumber.innerHTML);
const tomatoPrice = parseFloat(tomato.innerHTML);</p>
<p>const totalCost = 2 * cucumberPrice + 3 * tomatoPrice;</p>
<p>total.innerHTML = totalCost.toFixed(2);
</script></p>
黄瓜3.5元/斤 西红柿2.7元/斤  计算2斤黄瓜3斤西红柿总价

原文地址: https://www.cveoy.top/t/topic/nyuf 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录