gpt4 book ai didi

javascript - 将按钮的值传给JS加载DIV内容

转载 作者:行者123 更新时间:2023-11-30 11:27:24 25 4
gpt4 key购买 nike

我正在尝试将所选选项的值发送到新的 DIV 以动态加载下拉菜单。DIV 被触发,但所需的值不会发送到这个新的 DIV。问题是 + $("#add_bedrijf_"+ [i]).val()

发送此邮件的正确方式是什么?(其他代码用于操作不同的类,这是正确的。)

 <div class="form-group col-md-6">
<div class="form-group has-warning-add has-feedback" id="div_add_bedrijf" data-toggle="buttons">';
$c = 0;

foreach ($_SESSION['bedrijf'] as $value)
{
echo '<label class="btn btn-secondary" for="add_bedrijf_<?php echo $c;?>"><input type="radio" id="add_bedrijf_<?php echo $c;?>" name="add_bedrijf" value="'.$value.'" onmousemove="validate_add()" onblur="validate_add()"><img src="images/logo_'.$value.'_small.png" height="30"></label>';
$c++;
}
echo '<span class="glyphicon glyphicon-warning-sign form-control-feedback" id="add_bedrijf_status"></span>
</div>
</div>

<script type="text/javascript">
function validate_add()
{
// Parent div of all buttons
let div_add_bedrijf = document.getElementById('div_add_bedrijf');
// Status div
let add_bedrijf_status = document.getElementById('add_bedrijf_status');
// A list with all the inputs that start the with id "add_bedrijf_"
let elements = document.querySelectorAll('input[id^="add_bedrijf_"]');
for(let i = 0; i < elements.length; i++) {
let element = elements[i];
// If the element is checked
if(element.checked) {
div_add_bedrijf.className = "form-group has-success has-feedback";
add_bedrijf_status.className = "glyphicon glyphicon-ok form-control-feedback";
$("#add_groep").load("includes/dynamic_drop/magazijn_magazijn_groep.php?choice=" + $("#add_bedrijf_" + [i]).val())
// We found one was selected, so exit the loop
return;
} else {
div_add_bedrijf.className = "form-group has-warning has-feedback";
add_bedrijf_status.className = "glyphicon glyphicon-warning-sign form-control-feedback";
}
}
}
</script>

最佳答案

您是否尝试过 + element.value 而不是 + $("#add_bedrijf_"+ [i]).val()

https://www.w3schools.com/jsref/prop_radio_value.asp

关于javascript - 将按钮的值传给JS加载DIV内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47496069/

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