custom tags not working in ie8

你说的曾经没有我的故事 提交于 2019-11-28 05:31:42

问题


I tried making custom tags so that uses can enter text that displays something with red or bold etc when rendered as HTML for eg,

<rb>text here becomes red and bold</rb> and goes to default here

this gets rendered in a div with class 'note' and i have the following css set up

.note rb
{
    color:Red;
    font-weight:bold;
}

It works in ie9, chrome, firefox but doesnt work in ie8. How can I make it work there?


回答1:


To please the senior browsers ( IE8 and older) I would just go with something like:

HTML:

<span class="RB">text here becomes red and bold</span> and goes to default here

CSS:

.RB {color:Red; font-weight:bold; }

This targets all the RB classes. So you only need to wrap everything inside

<span class="RB"> </span>




回答2:


if you don't mind a little javascript:

<!--[if lt IE 9]>
<script>
document.createElement("rb");
</script>
<![endif]-->

if you want to add several elements/tags, you can:

<!--[if lt IE 9]>
<script>
// bold, italic, underlined, striked
els = ['rb', 'ri', 'ru', 'rs'];
for(i = 0; i < els.length; i++) {
    document.createElement(els[i]);
    }
</script>
<![endif]-->

Update

Looks like ability to define custom elements is in the work (W3C Working Draft 6 June 2013)

Some projects that use this:

  • Google’s Polymer
  • Mozilla’s X-Tags
  • Mozilla’s Brick

See also:

  • Introducing Brick: Minimal-markup Web Components for Faster App Development (Aug 27, 2013)
  • Custom Elements: defining new elements in HTML (Aug 28, 2013)
  • Custom Elements: a web components gallery for modern web apps


来源:https://stackoverflow.com/questions/6854757/custom-tags-not-working-in-ie8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!