自定义html标签 - 有没有更好的方法? [英] Custom html tags -- Is there a better way?

查看:144
本文介绍了自定义html标签 - 有没有更好的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



基本上,
让我们说你的浏览器,然后你会看到这在你的页面的某处出现了这个文本。

 < p>然后汤姆克鲁斯吞噬了这个星球。< p为H. 

该插件正在扫描文本并会找到Tom Cruise。一旦在我的服务器上唾弃AJAX,并返回一个HTML页面将被显示在工具提示中。



我最初的标记是这样的

 < p>然后< span class =ajax subtleShadow>汤姆克鲁斯< / span>,吞噬了这个星球。< / p> ; 

虽然我发现这可能会出错,但如果网页的span css存在奇怪或嵌套在一个跨度奇怪的东西像边界。



我的解决方案是INVENT一个新的html标签。像这样......

 < p>然后< fhwdgads class =ajax subtleShadow>汤姆克鲁斯< fhwdgads>,吞噬了这个星球。< / p> 

尽管快速搜索引导我得出结论:互联网我是这样做的。



是否有另一种方法可以标记自定义标签的内嵌文本创建? 编辑 a href =http://i.imgur.com/RasEH.jpg =nofollow>链接到嵌套跨度中断开按钮的视图。

解决方案

确实不能保证< fhwdgads> 永远不会被识别为具有特殊语义或格式的标记。如果你使用非常混乱的标签名称,这可能是不可能的,但是真的吗?人们倾向于在发明标签时使用助记名称,然后在当前或未来的规范或浏览器中与标签发生冲突的真实机会。 另外,一些旧版本的IE完全忽略无法识别的标签,例如不要让你风格化他们。这可以避免使用 document.createElement()为每个标签名称使用一次。



使用 span div 在实践中是安全的。没有理由认为浏览器在默认情况下对它们有一些奇特的格式。正如我们不停止使用 h1 ,尽管理论上它可能会使内容变成粉红色并闪烁。如果你期望浏览器厂商完全疯狂是不可能的。



使用类是另外一回事,但只是在其他样式表使用相同的意义上类名称与你一样。您可能需要在其他作者样式表干扰您的环境中工作。但这只是要求谨慎。它不会使用错误的工具创建 span div 元素。


I am attempting to complete a browser plugin that will analyze text and mark it in some fashion.

Basically, let's say your browsing and you see this come across this text somewhere in your page.

<p>and then Tom Cruise, devoured the planet.</p>

The plugin is scanning the text and will find "Tom Cruise." Once moused over spit AJAX at my server and return a HTML page to be will be displayed in a tool tip.

I originally marked it like so

<p>and then <span class="ajax subtleShadow">Tom Cruise</span>, devoured the planet.</p>

Though i am discovering that this can go wrong, if the webpage has strange span css or if its nested in a span with strange things like borders.

My solution was to INVENT a new html tags. like so...

<p>and then <fhwdgads class="ajax subtleShadow">Tom Cruise</fhwdgads>, devoured the planet.</p>

Though a quick search lead me to the conclusion that "the internet" would come after me with pitchforks should I do so.

Is there another way to mark inline text creation of custom tags?

EDIT : Link to a view of the broken button in the nested spans.

解决方案

There’s really no guarantee that <fhwdgads> is never recognized as a tag with some special semantics or formatting. It might be improbable if you use a very messy tag name, but would you, really? People tend to use mnemonic names when they invent tags, and then there’s a real chance of clashing with tags in some current or future spec or browser.

Moreover, some old versions of IE ignore unrecognized tags completely, e.g. do not let you style them. This can be avoided using document.createElement() once for each tag name, though.

Using span or div is as such safe in practice. There is no reason to think that browsers have some fancy formatting for them by default. Just as we don’t stop using h1 even though it is theoretically possible that it will make the content pink and blinking. It’s impossible to be foolproof if you expect browser vendors to be totally crazy.

Using classes is a different matter, though only in the sense that other style sheets play with the same class names as you. You might need to work in an environment where other author style sheets interfere with yours. But this just calls for caution; it does not make a span or div element with a class the wrong tool.

这篇关于自定义html标签 - 有没有更好的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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