亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從 Input type="number" 獲取值,并將其提供給其他輸入的 value 屬性

如何從 Input type="number" 獲取值,并將其提供給其他輸入的 value 屬性

翻閱古今 2021-08-20 17:02:48
我正在嘗試編輯我的表格行。當我嘗試編輯它時,以前的值沒有更新到新輸入框。我想在新輸入框中獲取數字。我嘗試通過,value="' + $(this).text() + '">'但它適用于type="text",而它不適用于 type="number"。任何人都可以請幫忙。// Edit row on edit button click$(document).on("click", ".edit", function(){            $(this).parents("tr").find("td:not(:last-child, :nth-last-child(2))").each(function(){        $(this).html('<input type="text" class="heading_label-box" value="' + $(this).text() + '">');    });      $(this).parents("tr").find("td:nth-last-child(3)").each(function(){        $(this).html('<input type="number" class="heading_total-weight" value="' + $(this).text() + '">');    });        $(this).parents("tr").find(".add, .edit").toggle();    $(".add-heading, .add-point").attr("disabled", "disabled");});我試過$(this).val(), $(this).value(),但無法獲得價值。
查看完整描述

2 回答

?
大話西游666

TA貢獻1817條經驗 獲得超14個贊

由于您要使用輸入更新的對象是 TD,您應該這樣做:


$(document).on("click", ".edit", function(){        

    $(this).parents("tr").find("td:not(:last-child, :nth-last-child(2))").each(function(){

        let thisVal = $(this).text();

        let inputObj = $('<input type="text" class="heading_label-box"/>');

        inputObj.val(thisVal);

        $(this).html('');

        $(this).append(inputObj);

    });  

    $(this).parents("tr").find("td:nth-last-child(3)").each(function(){

        let thisVal = $(this).text();

        let inputObj = $('<input type="number" class="heading_total-weight"/>');

        inputObj.val(thisVal);

        $(this).html('');

        $(this).append(inputObj);

    });    

    $(this).parents("tr").find(".add, .edit").toggle();

    $(".add-heading, .add-point").attr("disabled", "disabled");

});


查看完整回答
反對 回復 2021-08-20
?
蠱毒傳說

TA貢獻1895條經驗 獲得超3個贊

似乎輸入類型編號不起作用。

$(this).html('<input type="number" class="heading_total-weight" value="' + $(this).text() + '">');

.text() 返回字符串,因此它不起作用。


查看完整回答
反對 回復 2021-08-20
  • 2 回答
  • 0 關注
  • 273 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號