我已经在客户端创建了单选按钮,当我单击它时,它应该显示我现有的 div,即 ifPrint
请看看我正在尝试的代码:
单选按钮创建:
var optiondiv = document.getElementById('option-div');
document.getElementById('create').onclick = function () {
newopt = document.getElementById('new-option').value;
if(newopt){
var input = document.createElement('input'),
label = document.createElement('label');
input.type = "radio";
input.setAttribute("value", newopt);
input.setAttribute("checked", true);
input.setAttribute("name", "radio-name");
label.appendChild(input);
label.innerHTML += newopt+'<br>';
optiondiv.appendChild(label);
document.getElementById('new-option').value = '';
$.post(
"equipments1.php",
{
"newopt": newopt
},
function(data) {
if(data.success){
alert('Successful Added To dB');
document.getElementById('newopt').checked = false;
// if (document.getElementById('newopt').checked) {
//document.getElementById('ifPrint').style.display = 'block';
//$(#ifPrint).show();
//$(#ifPrint).show();
}else{
alert('Not Add To DB');
}
});
}else{
alert('Please Enter Radio Button Value.');
return false;
}
};
显示 Div ifPrint 的新函数:
$('input[type=radio][name=newopt]').change(function() {
$(#ifPrint).show();
});
如果可以请指导
最佳答案
您需要使用单击而不是更改,并且代码中缺少引号,如果元素是在动态之后创建的,最好使用“on”而不是“click”函数
$('body').on('click','input[type=radio][name=newopt]',function () {
$('#ifPrint').show();
});
关于javascript - 在动态创建的单选按钮选择上显示 Div (PHP-AJAX),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39844070/