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

标签 javascript jquery html

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

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/

相关文章:

javascript - 测试位置jquery

javascript - 谷歌翻译风格选择菜单

javascript - 尝试在网站上抓取由谷歌地图API生成的动态数据,但正常抓取返回空白

javascript - 如何在下拉列表中显示值?

javascript - 如何让我的 CSS slider 自动播放?

JQuery - Microsoft JScript 运行时错误 : Object expected

javascript - 如何使用javaScript将文本高度调整为div

javascript - 在不使用 html 的情况下为文本着色

javascript - Canvas : why is this color difference?

javascript - 如何使用js删除json中特定索引处的字符?