Javascript keyup功能第一次按键不工作两个按下工作

时间:2017-02-10 13:50:01

标签: javascript onchange keyup

我的代码工作但一半工作:( 需要完成的操作是对输入的数据执行各种操作并编写集合。但是,当按下键时,执行先前的操作。 注意:format.money和会计js中的unformat。



function inputkopyala(){
    var t = $('#toplam').val();
    if ($('#toplam1').val() == null) {
        var t1 = 0;
    }
    else {
        var t1 = $('#toplam1').val();
    }
    if ($('#toplam2').val() == null) {
        var t2 = 0;
    }
    else {
        var t2 = $('#toplam2').val();
    }
    if ($('#toplam3').val() == null) {
        var t3 = 0;
    }
    else {
        var t3 = $('#toplam3').val();
    }
    if ($('#toplam4').val() == null) {
        var t4 = 0;
    }
    else {
        var t4 = $('#toplam4').val();
    }
    if ($('#toplam5').val() == null) {
        var t5 = 0;
    }
    else {
        var t5 = $('#toplam5').val();
    }
    if ($('#toplam6').val() == null) {
        var t6 = 0;
    }
    else {
        var t6 = $('#toplam6').val();
    }
    if ($('#toplam7').val() == null) {
        var t7 = 0;
    }
    else {
        var t7 = $('#toplam7').val();
    }
    if ($('#toplam8').val() == null) {
        var t8 = 0;
    }
    else {
        var t8 = $('#toplam8').val();
    }
    if ($('#toplam9').val() == null) {
        var t9 = 0;
    }
    else {
        var t9 = $('#toplam9').val();
    }
    if ($('#toplam10').val() == null) {
        var t10 = 0;
    }
    else {
        var t10 = $('#toplam10').val();
    }
    if ($('#toplam11').val() == null) {
        var t11 = 0;
    }
    else {
        var t11 = $('#toplam11').val();
    }
    if ($('#toplam12').val() == null) {
        var t12 = 0;
    }
    else {
        var t12 = $('#toplam12').val();
    }
    if ($('#toplam13').val() == null) {
        var t13 = 0;
    }
    else {
        var t13 = $('#toplam13').val();
    }
    if ($('#toplam14').val() == null) {
        var t14 = 0;
    }
    else {
        var t14 = $('#toplam14').val();
    }
    if ($('#toplam15').val() == null) {
        var t15 = 0;
    }
    else {
        var t15 = $('#toplam15').val();
    }
    if ($('#toplam16').val() == null) {
        var t16 = 0;
    }
    else {
        var t16 = $('#toplam16').val();
    }
    if ($('#toplam17').val() == null) {
        var t17 = 0;
    }
    else {
        var t17 = $('#toplam17').val();
    }
    if ($('#toplam18').val() == null) {
        var t18 = 0;
    }
    else {
        var t18 = $('#toplam18').val();
    }
    if ($('#toplam19').val() == null) {
        var t19 = 0;
    }
    else {
        var t19 = $('#toplam19').val();
    }
    if ($('#toplam20').val() == null) {
        var t20 = 0;
    }
    else {
        var t20 = $('#toplam20').val();
    }
    if ($('#toplam21').val() == null) {
        var t21 = 0;
    }
    else {
        var t21 = $('#toplam21').val();
    }
    if ($('#toplam22').val() == null) {
        var t22 = 0;
    }
    else {
        var t22 = $('#toplam22').val();
    }
    if ($('#toplam23').val() == null) {
        var t23 = 0;
    }
    else {
        var t23 = $('#toplam23').val();
    }
    if ($('#toplam24').val() == null) {
        var t24 = 0;
    }
    else {
        var t24 = $('#toplam24').val();
    }
    if ($('#toplam25').val() == null) {
        var t25 = 0;
    }
    else {
        var t25 = $('#toplam25').val();
    }
    if ($('#toplam26').val() == null) {
        var t26 = 0;
    }
    else {
        var t26 = $('#toplam26').val();
    }
    if ($('#toplam27').val() == null) {
        var t27 = 0;
    }
    else {
        var t27 = $('#toplam27').val();
    }
    if ($('#toplam28').val() == null) {
        var t28 = 0;
    }
    else {
        var t28 = $('#toplam28').val();
    }
    if ($('#toplam29').val() == null) {
        var t29 = 0;
    }
    else {
        var t29 = $('#toplam29').val();
    }
    if ($('#toplam30').val() == null) {
        var t30 = 0;
    }
    else {
        var t30 = $('#toplam30').val();
    }
    var sonuc;
    sonuc = accounting.formatMoney(accounting.unformat(t)+accounting.unformat(t1)+accounting.unformat(t2)+accounting.unformat(t3)+accounting.unformat(t4)+accounting.unformat(t5)+accounting.unformat(t6)+accounting.unformat(t7)+accounting.unformat(t8)+accounting.unformat(t9)+accounting.unformat(t10)+accounting.unformat(t11)+accounting.unformat(t12)+accounting.unformat(t13)+accounting.unformat(t14)+accounting.unformat(t15)+accounting.unformat(t16)+accounting.unformat(t17)+accounting.unformat(t18)+accounting.unformat(t19)+accounting.unformat(t20)+accounting.unformat(t21)+accounting.unformat(t22)+accounting.unformat(t23)+accounting.unformat(t24)+accounting.unformat(t25)+accounting.unformat(t26)+accounting.unformat(t27)+accounting.unformat(t28)+accounting.unformat(t29)+accounting.unformat(t30));
    $('#yekun').html(""+sonuc +"");
    var v = $('#vergi').val();
    if ($('#vergi1').val() == null) {
        var v1 = 0;
    }
    else {
        var v1 = $('#vergi1').val();
    }
    if ($('#vergi2').val() == null) {
        var v2 = 0;
    }
    else {
        var v2 = $('#vergi2').val();
    }
    if ($('#vergi3').val() == null) {
        var v3 = 0;
    }
    else {
        var v3 = $('#vergi3').val();
    }
    if ($('#vergi4').val() == null) {
        var v4 = 0;
    }
    else {
        var v4 = $('#vergi4').val();
    }
    if ($('#vergi5').val() == null) {
        var v5 = 0;
    }
    else {
        var v5 = $('#vergi5').val();
    }
    if ($('#vergi6').val() == null) {
        var v6 = 0;
    }
    else {
        var v6 = $('#vergi6').val();
    }
    if ($('#vergi7').val() == null) {
        var v7 = 0;
    }
    else {
        var v7 = $('#vergi7').val();
    }
    if ($('#vergi8').val() == null) {
        var v8 = 0;
    }
    else {
        var v8 = $('#vergi8').val();
    }
    if ($('#vergi9').val() == null) {
        var v9 = 0;
    }
    else {
        var v9 = $('#vergi9').val();
    }
    if ($('#vergi10').val() == null) {
        var v10 = 0;
    }
    else {
        var v10 = $('#vergi10').val();
    }
    if ($('#vergi11').val() == null) {
        var v11 = 0;
    }
    else {
        var v11 = $('#vergi11').val();
    }
    if ($('#vergi12').val() == null) {
        var v12 = 0;
    }
    else {
        var v12 = $('#vergi12').val();
    }
    if ($('#vergi13').val() == null) {
        var v13 = 0;
    }
    else {
        var v13 = $('#vergi13').val();
    }
    if ($('#vergi14').val() == null) {
        var v14 = 0;
    }
    else {
        var v14 = $('#vergi14').val();
    }
    if ($('#vergi15').val() == null) {
        var v15 = 0;
    }
    else {
        var v15 = $('#vergi15').val();
    }
    if ($('#vergi16').val() == null) {
        var v16 = 0;
    }
    else {
        var v16 = $('#vergi16').val();
    }
    if ($('#vergi17').val() == null) {
        var v17 = 0;
    }
    else {
        var v17 = $('#vergi17').val();
    }
    if ($('#vergi18').val() == null) {
        var v18 = 0;
    }
    else {
        var v18 = $('#vergi18').val();
    }
    if ($('#vergi19').val() == null) {
        var v19 = 0;
    }
    else {
        var v19 = $('#vergi19').val();
    }
    if ($('#vergi20').val() == null) {
        var v20 = 0;
    }
    else {
        var v20 = $('#vergi20').val();
    }
    if ($('#vergi21').val() == null) {
        var v21 = 0;
    }
    else {
        var v21 = $('#vergi21').val();
    }
    if ($('#vergi22').val() == null) {
        var v22 = 0;
    }
    else {
        var v22 = $('#vergi22').val();
    }
    if ($('#vergi23').val() == null) {
        var v23 = 0;
    }
    else {
        var v23 = $('#vergi23').val();
    }
    if ($('#vergi24').val() == null) {
        var v24 = 0;
    }
    else {
        var v24 = $('#vergi24').val();
    }
    if ($('#vergi25').val() == null) {
        var v25 = 0;
    }
    else {
        var v25 = $('#vergi25').val();
    }
    if ($('#vergi26').val() == null) {
        var v26 = 0;
    }
    else {
        var v26 = $('#vergi26').val();
    }
    if ($('#vergi27').val() == null) {
        var v27 = 0;
    }
    else {
        var v27 = $('#vergi27').val();
    }
    if ($('#vergi28').val() == null) {
        var v28 = 0;
    }
    else {
        var v28 = $('#vergi28').val();
    }
    if ($('#vergi29').val() == null) {
        var v29 = 0;
    }
    else {
        var v29 = $('#vergi29').val();
    }
    if ($('#vergi30').val() == null) {
        var v30 = 0;
    }
    else {
        var v30 = $('#vergi30').val();
    }
    var vergiler;
    vergiler = accounting.formatMoney(accounting.unformat(v)+accounting.unformat(v1)+accounting.unformat(v2)+accounting.unformat(v3)+accounting.unformat(v4)+accounting.unformat(v5)+accounting.unformat(v6)+accounting.unformat(v7)+accounting.unformat(v8)+accounting.unformat(v9)+accounting.unformat(v10)+accounting.unformat(v11)+accounting.unformat(v12)+accounting.unformat(v13)+accounting.unformat(v14)+accounting.unformat(v15)+accounting.unformat(v16)+accounting.unformat(v17)+accounting.unformat(v18)+accounting.unformat(v19)+accounting.unformat(v20)+accounting.unformat(v21)+accounting.unformat(v22)+accounting.unformat(v23)+accounting.unformat(v24)+accounting.unformat(v25)+accounting.unformat(v26)+accounting.unformat(v27)+accounting.unformat(v28)+accounting.unformat(v29)+accounting.unformat(v30));
    $('#topkdv').html(""+vergiler +"");
    document.urunformu.toplam.value = accounting.formatMoney(document.urunformu.adet.value*document.urunformu.birimfiyat.value)
    document.urunformu.vergi.value = accounting.formatMoney(document.urunformu.adet.value*document.urunformu.birimfiyat.value*document.urunformu.vergioran.value/100)
    document.getElementById("geneltoplam").innerHTML = accounting.formatMoney(accounting.unformat(document.getElementById("yekun").innerHTML)+accounting.unformat(document.getElementById("topkdv").innerHTML))
}
function inputkopyala1(){
    var t = $('#toplam').val();
    if ($('#toplam1').val() == null) {
        var t1 = 0;
    }
    else {
        var t1 = $('#toplam1').val();
    }
    if ($('#toplam2').val() == null) {
        var t2 = 0;
    }
    else {
        var t2 = $('#toplam2').val();
    }
    if ($('#toplam3').val() == null) {
        var t3 = 0;
    }
    else {
        var t3 = $('#toplam3').val();
    }
    if ($('#toplam4').val() == null) {
        var t4 = 0;
    }
    else {
        var t4 = $('#toplam4').val();
    }
    if ($('#toplam5').val() == null) {
        var t5 = 0;
    }
    else {
        var t5 = $('#toplam5').val();
    }
    if ($('#toplam6').val() == null) {
        var t6 = 0;
    }
    else {
        var t6 = $('#toplam6').val();
    }
    if ($('#toplam7').val() == null) {
        var t7 = 0;
    }
    else {
        var t7 = $('#toplam7').val();
    }
    if ($('#toplam8').val() == null) {
        var t8 = 0;
    }
    else {
        var t8 = $('#toplam8').val();
    }
    if ($('#toplam9').val() == null) {
        var t9 = 0;
    }
    else {
        var t9 = $('#toplam9').val();
    }
    if ($('#toplam10').val() == null) {
        var t10 = 0;
    }
    else {
        var t10 = $('#toplam10').val();
    }
    if ($('#toplam11').val() == null) {
        var t11 = 0;
    }
    else {
        var t11 = $('#toplam11').val();
    }
    if ($('#toplam12').val() == null) {
        var t12 = 0;
    }
    else {
        var t12 = $('#toplam12').val();
    }
    if ($('#toplam13').val() == null) {
        var t13 = 0;
    }
    else {
        var t13 = $('#toplam13').val();
    }
    if ($('#toplam14').val() == null) {
        var t14 = 0;
    }
    else {
        var t14 = $('#toplam14').val();
    }
    if ($('#toplam15').val() == null) {
        var t15 = 0;
    }
    else {
        var t15 = $('#toplam15').val();
    }
    if ($('#toplam16').val() == null) {
        var t16 = 0;
    }
    else {
        var t16 = $('#toplam16').val();
    }
    if ($('#toplam17').val() == null) {
        var t17 = 0;
    }
    else {
        var t17 = $('#toplam17').val();
    }
    if ($('#toplam18').val() == null) {
        var t18 = 0;
    }
    else {
        var t18 = $('#toplam18').val();
    }
    if ($('#toplam19').val() == null) {
        var t19 = 0;
    }
    else {
        var t19 = $('#toplam19').val();
    }
    if ($('#toplam20').val() == null) {
        var t20 = 0;
    }
    else {
        var t20 = $('#toplam20').val();
    }
    if ($('#toplam21').val() == null) {
        var t21 = 0;
    }
    else {
        var t21 = $('#toplam21').val();
    }
    if ($('#toplam22').val() == null) {
        var t22 = 0;
    }
    else {
        var t22 = $('#toplam22').val();
    }
    if ($('#toplam23').val() == null) {
        var t23 = 0;
    }
    else {
        var t23 = $('#toplam23').val();
    }
    if ($('#toplam24').val() == null) {
        var t24 = 0;
    }
    else {
        var t24 = $('#toplam24').val();
    }
    if ($('#toplam25').val() == null) {
        var t25 = 0;
    }
    else {
        var t25 = $('#toplam25').val();
    }
    if ($('#toplam26').val() == null) {
        var t26 = 0;
    }
    else {
        var t26 = $('#toplam26').val();
    }
    if ($('#toplam27').val() == null) {
        var t27 = 0;
    }
    else {
        var t27 = $('#toplam27').val();
    }
    if ($('#toplam28').val() == null) {
        var t28 = 0;
    }
    else {
        var t28 = $('#toplam28').val();
    }
    if ($('#toplam29').val() == null) {
        var t29 = 0;
    }
    else {
        var t29 = $('#toplam29').val();
    }
    if ($('#toplam30').val() == null) {
        var t30 = 0;
    }
    else {
        var t30 = $('#toplam30').val();
    }
    var sonuc;
    sonuc = accounting.formatMoney(accounting.unformat(t)+accounting.unformat(t1)+accounting.unformat(t2)+accounting.unformat(t3)+accounting.unformat(t4)+accounting.unformat(t5)+accounting.unformat(t6)+accounting.unformat(t7)+accounting.unformat(t8)+accounting.unformat(t9)+accounting.unformat(t10)+accounting.unformat(t11)+accounting.unformat(t12)+accounting.unformat(t13)+accounting.unformat(t14)+accounting.unformat(t15)+accounting.unformat(t16)+accounting.unformat(t17)+accounting.unformat(t18)+accounting.unformat(t19)+accounting.unformat(t20)+accounting.unformat(t21)+accounting.unformat(t22)+accounting.unformat(t23)+accounting.unformat(t24)+accounting.unformat(t25)+accounting.unformat(t26)+accounting.unformat(t27)+accounting.unformat(t28)+accounting.unformat(t29)+accounting.unformat(t30));
    var v = $('#vergi').val();
    if ($('#vergi1').val() == null) {
        var v1 = 0;
    }
    else {
        var v1 = $('#vergi1').val();
    }
    if ($('#vergi2').val() == null) {
        var v2 = 0;
    }
    else {
        var v2 = $('#vergi2').val();
    }
    if ($('#vergi3').val() == null) {
        var v3 = 0;
    }
    else {
        var v3 = $('#vergi3').val();
    }
    if ($('#vergi4').val() == null) {
        var v4 = 0;
    }
    else {
        var v4 = $('#vergi4').val();
    }
    if ($('#vergi5').val() == null) {
        var v5 = 0;
    }
    else {
        var v5 = $('#vergi5').val();
    }
    if ($('#vergi6').val() == null) {
        var v6 = 0;
    }
    else {
        var v6 = $('#vergi6').val();
    }
    if ($('#vergi7').val() == null) {
        var v7 = 0;
    }
    else {
        var v7 = $('#vergi7').val();
    }
    if ($('#vergi8').val() == null) {
        var v8 = 0;
    }
    else {
        var v8 = $('#vergi8').val();
    }
    if ($('#vergi9').val() == null) {
        var v9 = 0;
    }
    else {
        var v9 = $('#vergi9').val();
    }
    if ($('#vergi10').val() == null) {
        var v10 = 0;
    }
    else {
        var v10 = $('#vergi10').val();
    }
    if ($('#vergi11').val() == null) {
        var v11 = 0;
    }
    else {
        var v11 = $('#vergi11').val();
    }
    if ($('#vergi12').val() == null) {
        var v12 = 0;
    }
    else {
        var v12 = $('#vergi12').val();
    }
    if ($('#vergi13').val() == null) {
        var v13 = 0;
    }
    else {
        var v13 = $('#vergi13').val();
    }
    if ($('#vergi14').val() == null) {
        var v14 = 0;
    }
    else {
        var v14 = $('#vergi14').val();
    }
    if ($('#vergi15').val() == null) {
        var v15 = 0;
    }
    else {
        var v15 = $('#vergi15').val();
    }
    if ($('#vergi16').val() == null) {
        var v16 = 0;
    }
    else {
        var v16 = $('#vergi16').val();
    }
    if ($('#vergi17').val() == null) {
        var v17 = 0;
    }
    else {
        var v17 = $('#vergi17').val();
    }
    if ($('#vergi18').val() == null) {
        var v18 = 0;
    }
    else {
        var v18 = $('#vergi18').val();
    }
    if ($('#vergi19').val() == null) {
        var v19 = 0;
    }
    else {
        var v19 = $('#vergi19').val();
    }
    if ($('#vergi20').val() == null) {
        var v20 = 0;
    }
    else {
        var v20 = $('#vergi20').val();
    }
    if ($('#vergi21').val() == null) {
        var v21 = 0;
    }
    else {
        var v21 = $('#vergi21').val();
    }
    if ($('#vergi22').val() == null) {
        var v22 = 0;
    }
    else {
        var v22 = $('#vergi22').val();
    }
    if ($('#vergi23').val() == null) {
        var v23 = 0;
    }
    else {
        var v23 = $('#vergi23').val();
    }
    if ($('#vergi24').val() == null) {
        var v24 = 0;
    }
    else {
        var v24 = $('#vergi24').val();
    }
    if ($('#vergi25').val() == null) {
        var v25 = 0;
    }
    else {
        var v25 = $('#vergi25').val();
    }
    if ($('#vergi26').val() == null) {
        var v26 = 0;
    }
    else {
        var v26 = $('#vergi26').val();
    }
    if ($('#vergi27').val() == null) {
        var v27 = 0;
    }
    else {
        var v27 = $('#vergi27').val();
    }
    if ($('#vergi28').val() == null) {
        var v28 = 0;
    }
    else {
        var v28 = $('#vergi28').val();
    }
    if ($('#vergi29').val() == null) {
        var v29 = 0;
    }
    else {
        var v29 = $('#vergi29').val();
    }
    if ($('#vergi30').val() == null) {
        var v30 = 0;
    }
    else {
        var v30 = $('#vergi30').val();
    }
    var vergiler;
    vergiler = accounting.formatMoney(accounting.unformat(v)+accounting.unformat(v1)+accounting.unformat(v2)+accounting.unformat(v3)+accounting.unformat(v4)+accounting.unformat(v5)+accounting.unformat(v6)+accounting.unformat(v7)+accounting.unformat(v8)+accounting.unformat(v9)+accounting.unformat(v10)+accounting.unformat(v11)+accounting.unformat(v12)+accounting.unformat(v13)+accounting.unformat(v14)+accounting.unformat(v15)+accounting.unformat(v16)+accounting.unformat(v17)+accounting.unformat(v18)+accounting.unformat(v19)+accounting.unformat(v20)+accounting.unformat(v21)+accounting.unformat(v22)+accounting.unformat(v23)+accounting.unformat(v24)+accounting.unformat(v25)+accounting.unformat(v26)+accounting.unformat(v27)+accounting.unformat(v28)+accounting.unformat(v29)+accounting.unformat(v30));
    document.urunformu.toplam1.value = accounting.formatMoney(document.urunformu.adet1.value*document.urunformu.birimfiyat1.value)
    document.urunformu.vergi1.value = accounting.formatMoney(document.urunformu.adet1.value*document.urunformu.birimfiyat1.value*document.urunformu.vergioran1.value/100)
    $('#topkdv').html(""+vergiler +"");
    $('#yekun').html(""+sonuc +"");
    document.getElementById("geneltoplam").innerHTML = accounting.formatMoney(accounting.unformat(document.getElementById("yekun").innerHTML)+accounting.unformat(document.getElementById("topkdv").innerHTML))
}

//note: function inputkopyala2,3,4... continues to 29

<a href="javascript:void(0);" id="add_more" class="dt-button buttons-print btn btn-cerceve btn-xs ml">
    <i class="fa fa-plus"></i>
    &nbsp;&nbsp;
    <b>Add New</b>
</a>        

<script type="text/javascript">
    $(document).ready(function () {
        var maxAppend = 0;
        var degisken = 1;
        $("#add_more").click(function () {
            if (maxAppend >= 29) {
                alert("Maksimum Satır Sayısına Ulaştınız");
            }
            else {
                var add_new = $('<tr style=""><td><input type="text" name="item_name[]" required  placeholder="Ürün Adı" class="form-control"></td>\n\
                        <td><textarea style="height:40px;" rows="1" name="item_desc[]" placeholder="Ürün Açıklaması" class="form-control"></textarea></td>\n\
                        <td class="col-sm-1"><input onkeyup="inputkopyala' +degisken+ '()" onkeypress="return isNumberKey(event)" id="adet' +degisken+ '" type="text" data-parsley-type="number" name="quantity[]" placeholder="1" required class="form-control"></td>">\n\
                        <td class="col-sm-1"><input onkeyup="inputkopyala' +degisken+ '()" onkeypress="return isNumberKey(event)" id="birimfiyat' +degisken+ '" type="text" data-parsley-type="number" name="unit_cost[]" required placeholder="100 ₺" class="form-control"></td>\n\
                        <td class="col-sm-1"><select onchange="inputkopyala' +degisken+ '()" id="vergioran' +degisken+ '" name="item_tax_rate[]" class="form-control"><option value="0.00"><?= lang('none') ?></option>\n\\n\
            <?php
                $tax_rates = $this->db->get('tbl_tax_rates')->result();
                if (!empty($tax_rates)) {
                    foreach ($tax_rates as $v_tax) {
                    ?><option value="<?= $v_tax->tax_rate_percent ?>"><?= $v_tax->tax_rate_name ?></option><?php
                    }
                }
                ?></select></td>\n\
<td class="col-sm-1"><input id="vergi' +degisken+ '" type="text" name="tax" placeholder="0,00 ₺" readonly="" class="form-control"></td>\n\
<td class="col-sm-2"><input id="toplam' +degisken+ '" type="text" value="" name="tax" placeholder="0,00 ₺" readonly="" class="form-control toplam"></td>\n\
<td><a href="javascript:void(0);" class="remCF dt-button buttons-print btn btn-cerceve btn-xs mr"><i class="fa fa-times"></i></a></strong></td></tr>\n<br/>');
                degisken++;
                maxAppend++;
                $("#add_new").append(add_new);
            }
        });

        $("#add_new").on('click', '.remCF', function () {
            $(this).parent().parent().remove();
            degisken--;
            maxAppend--;
        });
    });
</script>
&#13;
&#13;
&#13;

0 个答案:

没有答案