gpt4 book ai didi

javascript - 当用户未选择下拉菜单中的选项时,如何提醒用户

转载 作者:行者123 更新时间:2023-12-02 14:19:47 25 4
gpt4 key购买 nike

我做了一个下拉菜单供用户选择,对于日期,它看起来像这样

enter image description here

如何提醒用户他们没有选择日期?月、日和年是 <select> 中的选项。元素

if(document.forms[0].checkindate.selectedIndex == 1) {
window.alert("You must select a date.");
return false;
}

我这样做了,但它不起作用。

最佳答案

给选择值为空并使用所需的 html 进行验证,例如

<select required>
<option value="">Month</option>
<option vslue="1">1</option>
</select>
<select required>
<option value="">Day</option>
<option vslue="1">1</option>
</select>
<select required>
<option value="">Year</option>
<option vslue="2016">2016</option>
</select>

或者使用 Javascript 或 jQuery 验证

关于javascript - 当用户未选择下拉菜单中的选项时,如何提醒用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38737062/

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