如何正确初始化JSHINT以查找id="text-intro"
脚本元素中的错误。如何完成function main()
以便
1)JSHINT的工作数据设置为id="text-intro"
。
2)JSHINT正确报告了一系列创建错误。
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="static.cache.cdn/js/jshint.js"></script>
</head>
<body>
<script id="text-intro" type="text/jshint">
// Hello.
//
// This is JSHint, a tool that helps to detect errors and potential
// problems in your JavaScript code.
//
// To start, simply enter some JavaScript anywhere on this page. Your
// report will appear on the right side.
//
// Additionally, you can toggle specific options in the Configure
// menu.
function main() {
return 'Hello, World!';
}
main();
</script>
<script type="text/javascript">
function main()
{
JSHINT. ... ?
}
main();
</script>
</body>
</html>
答案 0 :(得分:0)
我认为以下内容应该有效。
... truncated ...
<script type="text/javascript">
function main()
{
var scriptContent = document.getElementById('text-intro').textContent;
// You can symbols here for jsHint to assume are existing.
var globals = {
jQuery: true // Assume that jQuery is defined and don't report it as an error.
};
// Options to pass to jshint, see the docs. Here are some examples.
var options = {
/* '-W034': true */
/* 'camelcase': true */
/* 'predef': ['-window'] // remove a normally predefined var */
/* exported: ['MyVar'] // tell jshint this var is used in another file */
};
JSHINT(scriptContent, options, globals);
// Now do something with JSHINT.errors
}
main();
</script>