简体   繁体   English

如何使用Javascript来判断HTML属性是否存在

[英]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.

相关问题 在Javascript中。 我如何判断对象中是否存在字段? - In Javascript. how can I tell if a field exists inside an object? 如何判断“我的页面上是否存在 Javascript object”? - How can I tell 'Whether a Javascript object exists on my page'? 使用javascript,如何判断DOM中的HTML对象是否不在HTML源代码中? - Using javascript, how can I tell if an HTML object in the DOM is not in the HTML source code? 我怎么能告诉这个HTML代码中的javascript不影响所有按钮? - How can i tell the javascript in this html code not to influence all the buttons? 如何判断HTML5音频元素是否正在播放Javascript - How can I tell if an HTML5 Audio element is playing with Javascript 如何使用javascript检查HTML样式属性是否存在 - How to check if HTML style attribute exists with javascript 如何使用JavaScript(AJAX / jQuery)判断PHP $ _SESSION cookie是否存在? - How can I use JavaScript (AJAX/jQuery) to tell if a PHP $_SESSION cookie exists? 如何判断Javascript中是否存在窗口? - How to tell if a window exists in Javascript? 如何使用HTML或javascript将变量传递到action属性以进行下载(按钮/链接), - How can i pass a variable into action attribute for download (button/link) using HTML or javascript, 如何告诉Closure编译器单独文件中存在某些内容? - How can I tell Closure compiler that something exists in a separate file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM