我正在尝试构建一个平铺计算器,但似乎无法使用以下代码:
JQuery的:
$(document).ready(
function caculateForm() {
var length = document.getElementById('length').value;
var width = document.getElementById('width').value;
var size = document.getElementById('size').value;
var compute = (length * width) / (size / 100);
var total = compute * 100;
var allowance = (compute * 100) * .10;
allowance = Math.floor(total) + Math.floor(allowance + 1);
document.getElementById('total').value = Math.floor(total);
document.getElementById('allowance').value = allowance;
}
});
$(document).ready(
function clearFileInput(id) {
var elem = document.getElementById(id);
elem.parentNode.innerHTML = elem.parentNode.innerHTML;
}
});
这是我的jsfiddle
答案 0 :(得分:0)
在您的JSfiddle中,删除$(document).ready()
s:
function caculateForm() {
var length = document.getElementById('length').value;
var width = document.getElementById('width').value;
var size = document.getElementById('size').value;
var compute = (length * width) / (size / 100);
var total = compute * 100;
var allowance = (compute * 100) * .10;
allowance = Math.floor(total) + Math.floor(allowance + 1);
document.getElementById('total').value = Math.floor(total);
document.getElementById('allowance').value = allowance;
}
function clearFileInput(id) {
var elem = document.getElementById(id);
elem.parentNode.innerHTML = elem.parentNode.innerHTML;
}
并选择"没有包装头#34;选项..然后它应该工作
请参阅更新的小提琴:http://jsfiddle.net/f8ehW/3/
答案 1 :(得分:0)
更新了jQuery选择器。
清除功能需要重做,因此将其更改为
function clearFileInput() {
var elements = $("input[type=text], select");
elements.each(function(key, elem) {
elem.parentNode.innerHTML = elem.parentNode.innerHTML;
});
}