本文介绍了你知道一个HTML-Snippet验证器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种工具,可以让我检查某个HTML代码片段是否在合适的上下文中有效。



我会输入一些东西像

 < dd> 
我的定义
< div>
div inside& lt; dd& gt;允许$​​ b $ b< / div>
< / dd>

而不是整个文档。一个普通的验证器会抱怨缺失的dl-tag,但大多数时候我只想知道某个元素是否在另一个里面有效。




我会试着更详细地解释它。考虑以下代码片段:

 < form> 
< label>名称:< input />< / label>
< / form>

会有效,但要检查它我有两个选择:


  1. 验证整个文档:大多数时候这已经足够好了,但有时当我在处理部分HTML代码片段或嵌入式HTML时,会遇到一些麻烦。我必须将整个事件复制到一个新的HTML文档中并验证它。

  2. 只需复制代码片段并使用W3C验证程序进行验证,并忽略一些错误。
  3. >

基本上我想检查一个元素是否只包含允许包含的元素。

解决方案

您可以使用W3C验证程序检查代码段。



选择'通过直接输入验证'标签并选择更多选项。在那里有一个单选按钮来'验证HTML片段'。



它会将您的网页封装在有效的html中,因此您看到的错误仅仅是由于您的代码段。


I'm searching for a tool that would allow me to check whether a certain snippet of HTML would be valid in it's proper context.

I'd input something like

<dd>
    my definition 
    <div>
        div inside &lt;dd&gt; is allowed
    </div>
</dd>

instead of the whole document. A ordinary validator will complain about the missing dl-tag, but most of the times I just want to know whether a certain element is valid inside another one or not.


I'll try to explain it more detailed. Consider the following snippet:

<form>
    <label>Name: <input /></label>
</form>

Would be valid, but to check it I have two options:

  1. Validate the whole document: Most of the times this is good enough, but sometimes when I'm working on partial HTML snippets or embedded HTML it's quite some trouble. I'd have to copy the whole thing to a new HTML document and validate that.
  2. Just copy the snippet and validate it with the W3C validator and ignore some of the errors.

Basically I'd like to check, whether an element contains only elements it's allowed to contain.

解决方案

You can actually use the W3C validator to check a snippet.

Choose the 'Validate by Direct Input' tab and select More Options. In there there is a radio button to 'Validate HTML fragment'. http://validator.w3.org/#validate_by_input+with_options

It will wrap your page in valid html so the errors which you see are only due to your snippet.

这篇关于你知道一个HTML-Snippet验证器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 05:31