<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.
精彩评论