2014-09-01 52 views
0

如何正確初始化JSHINT以找到id="text-intro"腳本元素中的錯誤。如何完成function main()以便如何在網頁中安裝jshint

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> 
+0

你應該把你正在嘗試做的事情放在問題中,否則人們會認爲你只是想正常使用JSHint。 – drneel 2014-09-01 16:19:44

回答

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>