gpt4 book ai didi

javascript - 无法获取动态 document.getElementById 值

转载 作者:行者123 更新时间:2023-12-03 00:07:49 25 4
gpt4 key购买 nike

我在从表单中动态添加的行获取值时遇到问题。

我有一个“添加新行”按钮,我想通过使用 onChange 从新行获取值。

我不知道如何让它发挥作用

这段代码添加了我的行:

<script type="text/javascript">

$(document).ready(function(){
var counter = 1;
$(".add-row").click(function(){
var markup = "<tr><td><input type='hidden' name='record'></input></td><td><select name='pris["+ counter +"][type]'><option value='ordi'>Ordinaer</option><option value='barn'>Barn</option></select>Belop<input type='text' name='pris["+ counter +"][pris]' value='0' id='pris_"+ counter +"'></input>Gebyr kr.<input class='bless' type='text' id='Gebyr_"+ counter +"' readonly disabled size='5'></input></td></tr><tr><td>&nbsp;</td><td><input type='checkbox' name='pris["+ counter +"][1]' checked>Internett</input><input type='checkbox' name='pris["+ counter +"][2]' checked>Callsenter</input><input type='checkbox' name='pris["+ counter +"][3]'>Distribusjon</input><input type='checkbox' name='pris["+ counter +"][4]'>Lokal Billettluke</input></td></tr>";
counter++;
$("table tbody").append(markup);
});

我希望有一个这样的函数来处理我添加的所有行:

function Gebyr1(parameter) {
var c = 1;
var G10 = document.getElementById("pris_" + c).value;
if (G10 <= 99){var G10_2 = '15';}
else if (G10 >= 100 && G10 <= 249){var G10_2 = '20';}
else if (G10 >= 250 && G10 <= 449){var G10_2 = '25';}
else if (G10 >= 450 && G10 <= 699){var G10_2 = '30';}
else if (G10 >= 700 && G10 <= 949){var G10_2 = '35';}
else if (G10 >= 950 && G10 <= 1199){var G10_2 = '40';}
else if (G10 >= 1200 && G10 <= 1449){var G10_2 = '45';}
else if (G10 >= 1450 && G10 <= 1699){var G10_2 = '50';}
else if (G10 >= 1700 && G10 <= 1949){var G10_2 = '55';}
else if (G10 >= 1950 && G10 <= 2199){var G10_2 = '60';}
else if (G10 >= 2200 && G10 <= 2449){var G10_2 = '65';}
else if (G10 >= 2450 && G10 <= 2699){var G10_2 = '70';}
else if (G10 >= 2700 && G10 <= 2949){var G10_2 = '75';}
else if (G10 >= 2950 && G10 <= 3199){var G10_2 = '80';}
document.getElementById("Gebyr_" + c).value = G10_2;

最佳答案

使用 JQuery on() 而不是 click()

http://api.jquery.com/on/

$( "具有动态 dom 的容器的选择器").on( "click", "此容器内的新行按钮的选择器", function() { 控制台.log();});

关于javascript - 无法获取动态 document.getElementById 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54883742/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com