gpt4 book ai didi

javascript - 使用 JavaScript 或 jQuery 验证输入字段

转载 作者:行者123 更新时间:2023-11-28 07:12:13 24 4
gpt4 key购买 nike

我需要检查以确保四个字段具有某种值。我尝试过这些想法: Check whether a select box is empty How to tell if a DDL has options to select

我的代码目前是这样的:

    function goToConfirmStep() {
var isAllowed = false;
var type = $(".#tShowingType option:selected").val(); //DDL
var startDate = $("#startDate").text(); //date picker
var startTime = $("#startTime option:selected").val(); //DDL
var endTime = $("showingLength option:selected").val(); //DDL
if (type.val() ) { //&& //(type != null || type != "")
//(startDate.text() == "" || startDate.text() == null)) {//&&
//($('#startTime').has('option').length > 0) &&
//($('#endTime').has('option').length > 0)) {
alert("here");

我留下了评论,以便您可以了解我的尝试。

如果他们选择了值(“类型”和“开始时间”将在加载时选择一个值),我想移至下一页。我对其他人有一个警报,以防止他们在未填写字段的情况下继续前进。

最佳答案

您不应使用&&(和) 运算符,因为仅当所有字段均为空时才会显示警报。

应该是这样的:

function goToConfirmStep() {
var isAllowed = false;
var type = $(".#tShowingType option:selected").val(); //DDL
var startDate = $("#startDate").text(); //date picker
var startTime = $("#startTime option:selected").val(); //DDL
var endTime = $("showingLength option:selected").val(); //DDL

if (type == "" || startDate == "" || startTime == "" || endTime == "")
alert("please fill in the required fields");
else
goToNextStep();
}

关于javascript - 使用 JavaScript 或 jQuery 验证输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31194788/

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