简体   繁体   English

HTML和JavaScript验证问题:“元素脚本缺少必需的属性src”

[英]Html & JavaScript validation problem: “Element script is missing required attribute src”

While validating this snipit: 验证此snipit时:

<script type="text/javascript" charset="utf-8">
    /* <![CDATA[ */             
    jQuery.post('http://domain.com/dev/wp-admin/admin-ajax.php', {action: 'wpp_update', token: '2e85204387', id: 214});
    /* ]]> */

</script>

I am getting the validation error: "Element script is missing required attribute src." 我收到验证错误:“元素脚本缺少必需的属性src。”

The page has an HTML5 doctype and is encoded as utf-8. 该页面具有HTML5文档类型,并被编码为utf-8。

http://www.w3schools.com/TAGS/att_script_charset.asp http://www.w3schools.com/TAGS/att_script_charset.asp

The charset attribute specifies the character encoding used in an external script file (referred to by the src attribute). charset属性指定在外部脚本文件中使用的字符编码(由src属性引用)。

In other words, you shouldn't be using the charset attribute here, since you're not using an external script file. 换句话说,您不应该在这里使用charset属性,因为您没有使用外部脚本文件。 If you remove it, it'll validate. 如果删除它,它将验证。

Try moving the charset out of the 'script' tag and into a 'meta' tag. 尝试将字符集移出“脚本”标签,并移入“元”标签。 Charset is no longer supported as part of script in HTML5. 在HTML5中,不再支持将字符集作为脚本的一部分。 Also note 'type' is no longer required. 另请注意,不再需要“类型”。

Also you can remove the /* <![CDATA[ * / open and close. 您也可以删除/* <![CDATA[ * /打开和关闭。

See this link for a good example of handling character encoding. 有关处理字符编码的良好示例,请参见此链接 See this link for info on what attributes are supported in HTML5. 有关HTML5支持哪些属性的信息,请参见此链接

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

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