javascript - 如何在jquery中的if else条件中使字段成为必填字段

标签 javascript jquery html

我编写了一个 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/

相关文章:

javascript - 中文 SpeechSynthesis API -- Firefox

javascript - 脚本在第一次运行后停止工作

javascript - 无法更新点击事件上的按钮文本和字体图标

javascript - Js 对象项未设置为空对象

javascript - 寻找 Javascript Typed Arrays 仿真库

html - 调整 svg 文件中一组路径的大小

html - md-input-container 和标签未对齐

javascript - 尝试在不离开页面的情况下使用 jquery ajax 发布

javascript - 如何更改 dygraph 中的 x 轴位置?

javascript - Jquery 过滤表是否适合输入范围