[英]How can I tell of a HTML attribute exists or not, using Javascript
I'm trying to convert to HTML5, but to preserve the site experience for those that don't have all the HTML5 features, I would use a workaround. 我正在尝试转换为HTML5,但为了保留那些没有所有HTML5功能的网站体验,我会使用一种解决方法。 For example, how can I check if the HTML5 attribute contentEditable exists, so that if it doesn't, I can just create a textarea instead.
例如,如何检查HTML5属性contentEditable是否存在,如果不存在,我可以创建一个textarea。
Thaks! Thaks!
这可以提供帮助: http : //diveintohtml5.ep.io/detect.html
The following snippet checks if the 'contentEditable' property exists. 以下代码段检查'contentEditable'属性是否存在。
if('contentEditable' in element){
// contentEditable is available
}
else{
// create textarea
}
According to HTML5 Peeks, Pokes and Pointers : 根据HTML5 Peeks,Pokes和Pointers :
"isContentEditable" in document.createElement("a")
You can replace the document.createElement("a")
with any element, really, so if you already have an element you're working with, use that. 实际上,您可以使用任何元素替换
document.createElement("a")
,因此,如果您已经有正在使用的元素,请使用该元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.