[英]How to install jshint in a webpage
如何正確初始化JSHINT以在id="text-intro"
腳本元素中查找錯誤。 我如何完成function main()
以便
1)將JSHINT的工作數據設置為id="text-intro"
。
2)JSHINT正確報告了一系列的Founds錯誤。
<!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>
我認為,以下內容應該可以工作。
... 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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.