問題是我有一個JavaScript,看着幾個文本字段,並獲取每個的值。將它們加在一起,並在我的廢文本字段中給我一個總數。我想要做的是說,如果設置是A B C或D做總和,如果安裝程序的值是空白做其他。它似乎不想工作任何幫助將不勝感激。想不通爲什麼我的JavaScript不工作
$(document).ready(function(){
$('.scrap').click(function() {
var weld_scrap = $('.weld').val();
var dim_scrap = $('.dim').val();
var visual_scrap = $('.visual').val();
var adjust_scrap = $('.adjust').val();
var setup = $('.setup').val();
console.log(setup)
var sum = parseInt(weld_scrap) + parseInt(dim_scrap) + parseInt(visual_scrap) + parseInt(adjust_scrap) + parseInt(setup);
var other = parseInt(weld_scrap) + parseInt(dim_scrap) + parseInt(visual_scrap) + parseInt(adjust_scrap);
var A = '10';
var B = '10';
var C = '10';
var D = '10';
if (setup == 'A') {
setup = A;
$('.scrap').val(sum);
}else if (setup == 'B') {
setup = B;
$('.scrap').val(sum);
}else if (setup == 'C') {
setup = C;
$('.scrap').val(sum);
}else if (setup == 'D') {
setup = D;
$('.scrap').val(sum);
}else if (setup == '') {
$('.scrap').val(other);
}
});
});
我也試過這樣的,如果設置爲空
$(document).ready(function(){
$('.scrap').click(function() {
var weld_scrap = $('.weld').val();
var dim_scrap = $('.dim').val();
var visual_scrap = $('.visual').val();
var adjust_scrap = $('.adjust').val();
var setup = $('.setup').val();
console.log(setup)
var sum = parseInt(weld_scrap) + parseInt(dim_scrap) + parseInt(visual_scrap) + parseInt(adjust_scrap) + parseInt(setup);
var other = parseInt(weld_scrap) + parseInt(dim_scrap) + parseInt(visual_scrap) + parseInt(adjust_scrap);
var A = '10';
var B = '10';
var C = '10';
var D = '10';
if (setup == 'A') {
setup = A;
$('.scrap').val(sum);
}else if (setup == 'B') {
setup = B;
$('.scrap').val(sum);
}else if (setup == 'C') {
setup = C;
$('.scrap').val(sum);
}else if (setup == 'D') {
setup = D;
$('.scrap').val(sum);
}else if (setup === null) {
$('.scrap').val(other);
}
});
});
,這也
$(document).ready(function(){
$('.scrap').click(function() {
var weld_scrap = $('.weld').val();
var dim_scrap = $('.dim').val();
var visual_scrap = $('.visual').val();
var adjust_scrap = $('.adjust').val();
var setup = $('.setup').val();
console.log(setup)
var sum = parseInt(weld_scrap) + parseInt(dim_scrap) + parseInt(visual_scrap) + parseInt(adjust_scrap) + parseInt(setup);
var other = parseInt(weld_scrap) + parseInt(dim_scrap) + parseInt(visual_scrap) + parseInt(adjust_scrap);
var A = '10';
var B = '10';
var C = '10';
var D = '10';
if (setup == 'A') {
setup = A;
$('.scrap').val(sum);
}else if (setup == 'B') {
setup = B;
$('.scrap').val(sum);
}else if (setup == 'C') {
setup = C;
$('.scrap').val(sum);
}else if (setup == 'D') {
setup = D;
$('.scrap').val(sum);
}else if (setup == '0') {
$('.scrap').val(other);
}
});
});
這也太...
$(document).ready(function(){
$('.scrap').click(function() {
var weld_scrap = $('.weld').val();
var dim_scrap = $('.dim').val();
var visual_scrap = $('.visual').val();
var adjust_scrap = $('.adjust').val();
var setup = $('.setup').val();
console.log(setup)
var sum = parseInt(weld_scrap) + parseInt(dim_scrap) + parseInt(visual_scrap) + parseInt(adjust_scrap) + parseInt(setup);
var other = parseInt(weld_scrap) + parseInt(dim_scrap) + parseInt(visual_scrap) + parseInt(adjust_scrap);
var A = '10';
var B = '10';
var C = '10';
var D = '10';
if (setup == 'A') {
setup = A;
$('.scrap').val(sum);
}else if (setup == 'B') {
setup = B;
$('.scrap').val(sum);
}else if (setup == 'C') {
setup = C;
$('.scrap').val(sum);
}else if (setup == 'D') {
setup = D;
$('.scrap').val(sum);
}else if (setup === undefined) {
$('.scrap').val(other);
}
});
});
可以添加一個演示? – Mritunjay
您可以使用https://jsfiddle.net/進行演示 – Reeno
「似乎不想工作」是什麼意思? – entropic