我编写了一个 jquery 代码来显示、隐藏文本框取决于值。所以现在我想让该文本框在出现时强制显示。
我使用的代码如下。
document.getElementById('other').style.display = 'none';
$("#donate").change(function(){
var selected = $(this).val();
if(selected == 'item') {
document.getElementById('other').style.display = 'block';
} else {
document.getElementById('other').style.display = 'none';
}
});
如何强制执行。请任何人帮我做到这一点
最佳答案
$("#donate").change(function(){
if($("#other").is(":hidden")==false)
{
if($('#other').val()==""){
alert("Field is required");
return;
}
});
关于javascript - 如何在jquery中的if else条件中使字段成为必填字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41958781/