开发者

quotes inside array element [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.
<html>
<body>

<script type="text/javascript">
var i=blue;

var mycars = new Array();

mycars[0] = "'Sa'+i+'b'";


for (i=0;i<mycars.length;i++)
{
document.write(mycars[i] + "<br />");
}
</script>

</body>
</html>

i cant display mycars[0] element. How do i display mycars[0] element?

This is the script im trying to work with:

<script type="text/开发者_JAVA百科javascript">
function loadXMLDoc()
{
var xmlhttp;
xmlhttp=new XMLHttpRequest();
document.getElementById("rednoize").innerHTML="Checking..";
document.getElementById("hashcracking").innerHTML="Checking..";
var url=document.getElementById('ul').value;

if(url)
{
var md5_sites = new Array();
var results = new Array();
var md5_sites[0]= 'http://md5.rednoize.com/?p&s=md5&q='+ url +'&_=' ;
var md5_sites[1]= 'http://www.md5.hashcracking.com/search.php?md5='+ url ;

//rest of script

In firebug i get error as: missing ; before statement line 38


Use different logic. For example, something like this should work fine:

mycars[0] = "Sa{0}b";
for (i=0;i<mycars.length;i++) {
   document.write(mycars[i].replace("{0}", i) + "<br />");
}

This "template" logic is pretty generic, and better than the alternative which is eval.


It should be var i = "blue" and not blue unless blue is a global var. Also, it should be

mycars[0] = 'Sa'+i+'b';

To get Sablueb as output.


This line:

var i=blue;

… attempts to set the value of i to be the same as the value of blue, but blue hasn't been defined so you get an Uncaught ReferenceError and the script dies.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜