IE 11中li元素的value属性的规则是什么? [英] what's the rule about value attribute on li element in IE 11?

查看:90
本文介绍了IE 11中li元素的value属性的规则是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IE 11与Windows 7专业版SP1保持最新





问题是当我将li元素的值设置为1#ab时,#ab被截断,只剩下1,如下所示:



但是如果我将值设置为1a#b,一切都没问题,如下图所示:

我无法理解。
我在Chrome中试过这些情况,两者都没关系。
MS只表示一个li元素的值应该是一个整数,看起来没有更多:
http://msdn.microsoft.com/en-us/library/ie/ms535124(v = vs.85).aspx

解决方案

HTML规则是一个 li 元素可能具有属性,如果元素是 ol 元素的子元素,并且该属性的值必须是整数。 HTML5甚至规定了处理格式错误的值的规则。在 value =1#ab的情况下,应该使用值1,其余部分将被忽略。结果应该与 value =1a#b相同。但是,浏览器中的错误处理是已知的, HTML5正试图消除这些差异,但它还有很长的路要走。



你应该使用什么取决于你想要完成什么。当前的代码在两种方式中是无效的:属性在这里根本不被允许,如果元素是 ol ,属性值将是无效的。



如果您只是试图将数据存储在元素中,以用于脚本编写,请使用 data - * attribute 而不是,例如数据值


IE 11 with Windows 7 pro sp1 up to date

the problem is when I set the value of a li element to "1#ab", the "#ab" is been truncated, only "1" left, as following:

but if I set the value to "1a#b", everything is alright, as the following pics:

why this? I can't understand. I've tried these cases in Chrome, both are alright. the MS only said the value of a li element should be an integer, seems nothing more: http://msdn.microsoft.com/en-us/library/ie/ms535124(v=vs.85).aspx

解决方案

The HTML rule is that a li element may have the value attribute, if the element is a child of an ol element, and the value of the attribute must be an integer. HTML5 even prescribes rules for handling malformed values. In the case value="1#ab", the value 1 shall be used and the rest be ignored. The result should be the same for value="1a#b". However, error handling is known to vary in browsers; HTML5 is trying to remove the differences, but it’s a long way to go.

What you should use instead depends on what you are trying to accomplish. The current code is invalid in two ways: the value attribute is not permitted here at all, and if the element were a child of ol, the attribute value would be invalid.

If you are just trying to store data in an element, to be used in scripting, use a data-* attribute instead, e.g. data-value.

这篇关于IE 11中li元素的value属性的规则是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆