开发者

Compatibility issues with <a> and calling a function(); across different web browsers

I am new to javascript. I wrote th开发者_C百科e following function rollDice() to produce 5 random numbers and display them. I use an anchor with click event to call the function. Problem is, in Chrome it won't display, works fine in IE, in firefox the 5 values display and then the original page w/anchor appears! I am suspicious that my script tag is too general but I am really lost. Also if there is a display function that doesn't clear the screen first that would be great.

diceArray = new Array(5)

function rollDice() { var i;

for(i=0; i<5; i++) { diceArray[i]=Math.round(Math.random() * 6) % 6 + 1;

document.write(diceArray[i]); } }

when I click should display 5 rand variables


Do any errors appear in the Javascript consoles? I know that Chrome and Firefox both have them, so you should be able to see if any errors are being generated. You could also add a few alert('Hey') messages to check that it's even being launched in Chrome.

I do see that you don't have a semi-colon after your first line, but I don't know if that's a direct cut and paste, or if you typed it all in manually.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜