How can i validate the input from a html5 Datalist?

后端 未结 4 1293
遥遥无期
遥遥无期 2020-12-30 12:45

I would like to know how I can validate the input value that comes from a Datalist. I mean, if I have a Datalist where the user can start to write

4条回答
  •  离开以前
    2020-12-30 13:06

    Try this:

    
    

    And on form submit you can check:

    var val = $("#txt").val();
    
    var obj = $("#colours").find("option[value='" + val + "']");
    
    if(obj != null && obj.length > 0)
        alert("valid");  // allow form submission
    else
        alert("invalid"); // don't allow form submission
    

提交回复
热议问题