<h1>2 斤黄瓜 3 斤西红柿多少钱?</h1>
<p>黄瓜价格:<span>3.5</span> 元/斤</p>
<p>西红柿价格:<span>2.7</span> 元/斤</p>
<p>总价:<span></span> 元</p>
<script>
const cucumberPrice = document.querySelector('span:nth-of-type(1)');
const tomatoPrice = document.querySelector('span:nth-of-type(2)');
const totalPrice = document.querySelector('span:nth-of-type(3)');
<p>const cucumberPriceValue = parseFloat(cucumberPrice.innerHTML);
const tomatoPriceValue = parseFloat(tomatoPrice.innerHTML);</p>
<p>const totalWeight = 2 + 3;
const totalCucumberPrice = totalWeight * cucumberPriceValue;
const totalTomatoPrice = totalWeight * tomatoPriceValue;
const totalPriceValue = totalCucumberPrice + totalTomatoPrice;</p>
<p>totalPrice.innerHTML = totalPriceValue.toFixed(2);
</script></p>
黄瓜 3.5 元/斤,西红柿 2.7 元/斤,2 斤黄瓜 3 斤西红柿多少钱?

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

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