需要javascript语法帮助

时间:2010-10-14 13:17:43

标签: javascript

我目前正致力于在一个平台上工作,我可以插入要使用的js代码,由某些编译器验证,它会返回某些情况下的错误,如

  1. document.write('<IMG ALT="" BORDER="0" NAME="DCSIMG" WIDTH="1" HEIGHT="1" SRC="'+dcsSrc+'">');

      

    错误 *:314:9:document.write可以是eval的一种形式。

  2. 如果我们不使用可选的基数参数,
  3. parseInt函数抛出错误

  4. 有人知道语法或解决方案应该如何????

5 个答案:

答案 0 :(得分:1)

这些听起来像JSLint错误消息。您应该能够配置JSLint正在检查的错误。 See the Options section on this page,有关可以配置哪些选项的详细信息,例如tolerate eval

答案 1 :(得分:1)

有些Javascript实现拒绝允许document.write,因为它可能是一个固有的安全问题。

使用带有parseInt的基数非常重要。

以下是一个例子:

parseInt("010");      // assumes base 8 because of leading zero
8
parseInt("010", 10);  // force base 10
10

答案 2 :(得分:1)

请参阅:

  

http://www.jameswiseman.com/blog/2011/03/31/jslint-messages-document-write-can-be-a-form-of-eval/

溶液:

  

document.write("?") - &gt; document.body.innerHTML=?

答案 3 :(得分:0)

尝试在write方法之外评估此表达式。

答案 4 :(得分:0)

如果document.write不起作用,您可以尝试使用:

function addElement(dcsSrc) {
  var parentNode = document.getElementById('parentNode');
  var newimg = document.createElement('img');
  newimg.setAttribute('src',dcsSrc);
  newimg.setAttribute('alt','');
  newimg.setAttribute('border','0');
  newimg.setAttribute('name','dcsimg');
  newimg.setAttribute('width','1');
  newimg.setAttribute('height','1');
  parentNode.appendChild(newdiv);
}
相关问题