dougan4884 2014-01-31 17:11
浏览 39
已采纳

禁用选择选项的简单HTML表单允许在Chrome和IE中提交。 在Firefox中正常工作

I have a simple HTML form that submits to another page. Select options are being used with one being 'disabled' and 'selected'. In Chrome and Internet Explorer this form is allowed to be submitted, but in Firefox it works correctly and tells me to select an option.

Code:

<form name=cars method=post action=submit.php>
    <select required>
        <option value="volvo" disabled="disabled" selected>Volvo</option>
        <option value="saab">Saab</option>
        <option value="vw">VW</option>
        <option value="audi">Audi</option>
        <input type=submit value=submit name=submit>
    </select> 
</form>

In FireFox, as expected, when I hit the submit button, I get the message:

"Please Select an item in the list."

On IE and Chrome it tries to submit to the submit page.

  • 写回答

2条回答 默认 最新

  • dongshuxi3105 2014-01-31 19:32
    关注

    Above solution will work in all browsers except IE 7-8-9, As required attribute;

    IE 10: works fine.
    IE 9: the required attribute doesn't trigger validation of a field.
    IE 7 & 8: the required attribute appears to prevent validation of a field.
    

    Ref 'required' attibute support in different browsers:

    http://html5test.com/compare/feature/form-select-required.html
    

    Alternative solution can be JQuery.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?