简体   繁体   English

通过Javascript将自定义属性添加到HTML元素

[英]Add a custom property to HTML element via Javascript

I am trying to add a custom element to Select html element. 我正在尝试为Select html元素添加自定义元素。

 var sel=document.getElementById("sel1");
  sel.setAttribute("customprop","blabla");

In chrome it works, in IE8 it doesn't. 在Chrome中它可以工作,在IE8中它没有。

NO JQUERY 没有遗憾

Check the question: Replace setAttribute with IE compatible script 检查问题: 用IE兼容脚本替换setAttribute

It seems you need to add doctype on top of your page: 您似乎需要在页面顶部添加doctype:

<!DOCTYPE html>

and then the following tag inside your head element to make setAttribute work: 然后在head元素中使用以下标记使setAttribute工作:

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM