输入长度和宽度 实时显示计算结果。 可在代码里设置不同材质立方值。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>木材计算器</title>
<style>
.container {
margin: 20px;
}
label {
display: inline-block;
width: 100px;
}
input {
width: 100px;
}
button {
margin-top: 10px;
}
#result {
margin-top: 20px;
}
</style>
<script>
function calculateCostAndPrice() {
var length = parseFloat(document.getElementById('length').value);
var width = parseFloat(document.getElementById('width').value);
var thickness = parseFloat(document.getElementById('thickness').value);
var material = document.getElementById('material').value;
var cubicValue = 0;
var cost = 0;
var sellingPrice = 0;
// Set different cubic values based on the material
if (material === 'pine') {
cubicValue = 10000;
} else if (material === 'beech') {
cubicValue = 15000;
}
// Calculate cost and selling price
cost = (length * width * thickness * cubicValue) / 1000000;
sellingPrice = cost * 1.5;
// Display the results
document.getElementById('cost').textContent = cost.toFixed(2);
document.getElementById('sellingPrice').textContent = sellingPrice.toFixed(2);
}
</script>
</head>
<body>
<div class="container">
<h1>木材计算器</h1>
<div>
<label for="length">长度:</label>
<input type="text" id="length" value="100">
</div>
<div>
<label for="width">宽度:</label>
<input type="text" id="width" value="100">
</div>
<div>
<label for="thickness">厚度:</label>
<select id="thickness">
<option value="2">2cm</option>
<option value="3">3cm</option>
<option value="5">5cm</option>
<option value="8">8cm</option>
</select>
</div>
<div>
<label for="material">材质:</label>
<select id="material">
<option value="pine">松木</option>
<option value="beech">白腊木</option>
</select>
</div>
<button onclick="calculateCostAndPrice()">计算</button>
<div id="result">
<p>成本:<span id="cost"></span>元</p>
<p>卖价:<span id="sellingPrice"></span>元</p>
</div>
</div>
</body>
</html>
不知道你这个问题是否已经解决, 如果还没有解决的话:说明:本作品为LILIXING.com原创作品,为了保障作品原创性,以下仅为首页部分代码供参考
<div id="container">
<div id="banner"> <img src="img/banner.jpg"> </div>
<div id="globallink"> <!--制作横向导航条,鼠标经过时荧光效果-->
<ul>
<li><a href="index.html">网站首页</a></li>
<li><a href="renwu.html">感动人物</a></li>
<li><a href="shunjian.html">动人瞬间</a></li>
<li><a href="shipin.html">感人视频</a></li>
<li><a href="tuji.html">感动图集</a></li>
</ul>
</div>
<div id="news">
<h3><span>英雄赞歌</span></h3>
<ul>
<li><span><a href="newsa.html"> - 最美方舱播音员</a></li>
<li><span><a href="newsb.html"> - 可爱的志愿者</a></li>
<li><span><a href="newsc.html"> - 勇挑重任的90后</a></li>
</ul>
<p><img src="img/t5.jpg" ><br>
<img src="img/t3.jpg" ></p>
</div>
<div id="story">
<h3>向英雄致敬</h3>
<p> <img src="img/t9.jpg" style="float:right;margin-left: 30px; width:200px;"> 在抗击新冠病毒疫情中,总有那么一些镜头让人泪目和深感温暖。每一个平凡的日子,都有那么一些人为了更好的明天,铭记着初心、担负着使命,选择了逆行,向这些逆风而行的勇士、奋斗在疫情防控一线的逆行天使致以崇高的敬意和衷心的感谢。感谢他们默默的坚守!
这世上哪有什么岁月静好,只是因为有人在替我们负重前行罢了,这世上哪有什么天生的英雄,只有因为人们需要,才有人愿意牺牲自己成为英雄。每个时代有每个时代的英雄,灾难面前,他们毅然逆向前行,不畏生死,他们当之无愧是这个时代的英雄,向英雄致敬。
<p>
<h3>疫情中的温暖和力量</h3>
<p> <img src="img/t4.jpg" style="float:right;margin-left: 30px; width:200px;"> 武汉老百姓在这场疫情中遭受了疫情带来的苦难,很多人为了亲情、友情付出了自己巨大的爱。还有很多人冒着生命的危险,冲在抗疫第一线。特别是当地的医护人员,他们是伟大的战士,是了不起的英雄。他们从疫情萌芽至今仍在坚守,仍在一线作战,他们的付出、牺牲、奉献,给了我们最大的感动,值得我们给予最高的礼遇,给予英雄的赞美。那些为我们雪地抱薪、深夜提灯的人,不仅值得我们感恩,更值得我。 </p>
</div>
<div id="thank">
<h3>永远铭记</h3>
<p>一方有难、八方支援,在这场没有硝烟的战场上,一张张冲到第一线的"最美逆行者"的照片刷屏朋友圈,他们毅然决然的背影让人感动、给人力量!历史将会铭记逆行者的无私付出,铭记逆行者的砥砺担当
。你们是中国坚实的脊梁! </p>
</div>
<div id="footer">
<p>抗击疫情</p>
</div>
</div>
根据问题和参考资料,可以创建一个动态HTML网页,其可以在用户输入长度和宽度时实时计算并显示结果,同时可以允许不同材料的立方值被设置。下面是一个示例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Dynamic HTML Page</title>
<style>
#container {
position: relative;
width: 100%;
height: 100vh;
}
#inputForm {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #f0f0f0;
padding: 20px;
box-shadow: 0 0 10px rgba(0,0,0,0.3);
}
form {
display: flex;
flex-direction: column;
align-items: center;
}
input[type="number"], select {
margin: 10px 0;
padding: 5px;
font-size: 16px;
text-align: center;
width: 100%;
}
input[type="button"] {
background-color: #4CAF50;
color: white;
padding: 10px;
border: none;
border-radius: 5px;
font-size: 20px;
cursor: pointer;
width: 100%;
}
input[type="button"]:hover {
background-color: #3e8e41;
}
#result {
margin: 20px 0;
text-align: center;
font-size: 24px;
font-weight: bold;
}
</style>
<script>
function calculate() {
// get input values
var length = document.getElementById("length").value;
var width = document.getElementById("width").value;
var material = document.getElementById("material").value;
// calculate volume
var volume = length * width * material;
// display result
document.getElementById("result").innerHTML = "The volume of the object is: " + volume;
}
</script>
</head>
<body>
<div id="container">
<div id="inputForm">
<form>
<label for="length">Length:</label>
<input type="number" name="length" id="length" onchange="calculate()" required>
<label for="width">Width:</label>
<input type="number" name="width" id="width" onchange="calculate()" required>
<label for="material">Material:</label>
<select name="material" id="material" onchange="calculate()" required>
<option value="1.0">Option 1</option>
<option value="1.5">Option 2</option>
<option value="2.0">Option 3</option>
</select>
<input type="button" value="Calculate" onclick="calculate()">
</form>
<div id="result">Please enter the dimensions and select the material to calculate the volume.</div>
</div>
</div>
</body>
</html>
代码的具体注释如下:
需要注意的是,以上示例代码仅供参考,具体实现可以根据实际需求进行调整。同时,为了确保用户输入正确和程序运行稳定,可以添加更多的验证和异常处理功能。
不是不想回答,只是这个太费时间了...