- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我是 JavaScript 新手。在给定甲板长度和宽度以及板的长度和宽度的情况下,我需要在计算需要多少板之后输出甲板的平面图。我的计算有效,但平面图输出不正确。我应该在输出计划的最后一个 for 循环中更改什么?
例如,如果一个 16x5 英尺的甲板有 10 个 8x1 英尺的木板,那么它可能看起来像这样
------------------
------------------
------------------
------------------
-------- --------
我的代码如下。我有一个 for 循环,它会根据电路板的长度给我一个“---”的电路板。在下面是我很伤心的 for 循环,试图根据甲板的宽度 (deckWidth) 和它的长度 (deckLength) 输出它的平面图。
$(document).ready(function() {
var deckArea;
var boardArea;
var numBoards;
var total;
var dLength;
var dWidth;
var bLength;
var bWidth;
var bPrice;
var planBoard = "";
$("#deckLength").keyup(function(){
if((isNaN(this.value) === false) && this.value !== "") {
dLength = parseFloat(this.value);
}
});
$("#deckWidth").keyup(function(){
if((isNaN(this.value) === false) && this.value !== "") {
dWidth = parseFloat(this.value);
}
});
$("#boardLength").keyup(function(){
if((isNaN(this.value) === false) && this.value !== "") {
bLength = parseFloat(this.value);
}
});
$("#boardWidth").keyup(function(){
if((isNaN(this.value) === false) && this.value !== "") {
bWidth = parseFloat(this.value);
}
});
$("#boardPrice").keyup(function(){
if((isNaN(this.value) === false) && this.value !== "") {
bPrice = parseFloat(this.value);
}
});
$("#deckcalc").on("click", function () {
numBoards = 0;
total = 0;
deckArea = dLength * dWidth;
boardArea = bLength * bWidth;
numBoards = deckArea/boardArea;
total = numBoards * bPrice;
//output total to screen
$("#cost").text("$"+total.toFixed(2));
$("#boardsNeeded").text(numBoards);
for(var y = 0; y < (bLength); y++) {
planBoard += "-";
}
for (var i = 0; i < dLength; i++) {
"<br>";
for (var x = 0; x < dWidth; x++) {
document.getElementById("plan").innerHTML = planBoard;
}
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label>deck Length</label><input type="text" id="deckLength" />
<label>deck Width</label><input type="text" id="deckWidth" />
<label>board Length</label><input type="text" id="boardLength" />
<label>board Width</label><input type="text" id="boardWidth" />
<label>board Price</label><input type="text" id="boardPrice" />
<button id="deckcalc">calcit</button>
<div id="plan"></div>
最佳答案
在您的循环中,您每次都在覆盖 .innerHTML 属性。您可能想使用 +=
添加到属性中:
此外,如评论中所述,您想添加 <br />
也标记到输出。
$(document).ready(function() {
var deckArea;
var boardArea;
var numBoards;
var total;
var dLength;
var dWidth;
var bLength;
var bWidth;
var bPrice;
var planBoard = "";
$("#deckLength").keyup(function(){
if((isNaN(this.value) === false) && this.value !== "") {
dLength = parseFloat(this.value);
}
});
$("#deckWidth").keyup(function(){
if((isNaN(this.value) === false) && this.value !== "") {
dWidth = parseFloat(this.value);
}
});
$("#boardLength").keyup(function(){
if((isNaN(this.value) === false) && this.value !== "") {
bLength = parseFloat(this.value);
}
});
$("#boardWidth").keyup(function(){
if((isNaN(this.value) === false) && this.value !== "") {
bWidth = parseFloat(this.value);
}
});
$("#boardPrice").keyup(function(){
if((isNaN(this.value) === false) && this.value !== "") {
bPrice = parseFloat(this.value);
}
});
$("#deckcalc").on("click", function () {
numBoards = 0;
total = 0;
deckArea = dLength * dWidth;
boardArea = bLength * bWidth;
numBoards = deckArea/boardArea;
total = numBoards * bPrice;
//output total to screen
$("#cost").text("$"+total.toFixed(2));
$("#boardsNeeded").text(numBoards);
for(var y = 0; y < (bLength); y++) {
planBoard += "-";
}
for (var i = 0; i < dLength; i++) {
planBoard += "<br>";
for (var x = 0; x < dWidth; x++) {
document.getElementById("plan").innerHTML += planBoard;
}
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label>deck Length</label><input type="text" id="deckLength" />
<label>deck Width</label><input type="text" id="deckWidth" />
<label>board Length</label><input type="text" id="boardLength" />
<label>board Width</label><input type="text" id="boardWidth" />
<label>board Price</label><input type="text" id="boardPrice" />
<button id="deckcalc">calcit</button>
<div id="plan"></div>
关于输出甲板平面图的 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30632206/
我是一个对 Haskell 感兴趣的初学者,我一直在尝试自己实现 flatmap (>>=) 以更好地理解它。目前我有 flatmap :: (t -> a) -> [t] -> [a] flatm
我正在尝试创建一个 searchBar,它通过带有请求的 MKLocalSearch 搜索地址并使用 RXSwift 并绑定(bind)到 RXCocoa 到目前为止,我已经完成了以下工作1.过滤和去
我正在使用 javascript/jquery(基于 DOM,而非 Canvas )构建某种拖放应用程序。 想法是能够在 3D 场景上拖动 div(在 3D 中旋转的 div)。 它在 2D 平面上工
我有这样的情况 class A { private B b; public B getB() { return b; } } 还有另一个B类 class B {
在链 obs1.flatmap(x -> obs2()).subscribe(sub) 如果 obs2 产生错误,它会立即调用 onError 在 sub 上。这是记录在案的: Note that i
在这篇文章中,平面图或平面图是指可以在平面(或等价物)中绘制的抽象图在球体上),以及根据特定此类绘图在每个顶点处的边的圆形顺序。这个额外的信息决定了球体上的嵌入(直到移动顶点和边,使得它们永远不会与任
我有一个 Flux 字符串。对于每个字符串,我必须进行远程调用。但问题是,进行远程调用的方法实际上返回的是 Mono 响应(显然,因为对应于单个请求,所以将有单个响应)。 处理此类情况的正确模式应该是
我对 MapPartition 没有搞清楚。请有人解释一下 Mappartition 的一些用例以及它与 FlatMap 有何不同? 最佳答案 区别在于方法的接口(interface)以及它们的调用方
我有这个问题,我有一个 RDD[(String,String, List[String]),我想“平面化”它以获得一个 RDD[(String ,字符串, 字符串)]: 例如: val x :RDD[
所以这将是我第一次无法通过搜索找到问题的答案.. 我对 D3 和 Javascript 总体来说还很陌生,我想要实现的是在浏览器中从 CAD 工具 (Autodesk Revit) 导出的一些曲线的可
我需要替换多年前构建的 Flash 查看器,以显示来自 AutoCAD 的交互式2D 平面图。 目前,AutoCAD 文件被读取并转换为 XML 文件,其中包含表示平面图对象的多边形的 X 和 Y 坐
我有 2 个 retrofit 电话需要进行 A 和 B: (A):返回一个ArrayList (B):获取 (A) 的结果,它是一个 ArrayList。 (B) 遍历 ArrayList 并使用每
我是一名优秀的程序员,十分优秀!