0

So all the things that you gave me bellow worked great, thank you. After adding what you all gave me I added the rest of the things that I need to and now it wont work. Please help.

<h2 style="font-size:16px !important">Did You Know?</h2>
<p style="float:right;" id="dyk"></p> 

<body onload="myFunction()">

<script>
function myFunction()
{
var x=document.getElementById("dyk")
var myTips=new Array();
myTips[1]="bob products have an average rating of 4.8 out of 5 stars. <a     href="http://www.bob .com/us/en/home/products/complete#reviewTabs">Take a look!</a>";
myTips[2]="You can get free stuff by posting on the community! Check out our <a     href="https://community.bob .com/t5/Community-Announcements/Announcing-the-bob -VIP-Program/m-    p/20652#M119">VIP Program!</a>";
myTips[3]="We want to know what you think!  Would you like to <a     href="http://www.bob .com/En_US/bv.html?    utm_source=community&utm_medium=dyk&utm_campaign=dyk">write a review?</a>";
myTips[4]="bob is a member of the <a href="http://www.antispywarecoalition.org/">Anti-    Spyware Coalition</a>, a group dedicated to controlling spyware and other potentially unwanted     technologies.";
myTips[5]="bob products are all fully compatible with Windows 8.";
myTips[6]="<a href="http://www.bob .com/us/en/home/products/complete?    utm_source=community&utm_medium=dyk&utm_campaign=dyk">bob bob Complete</a> offers 25     GB of storage and password management in addition to protection from viruses and other     threats.";
myTips[7]="PCWorld called bob mobile protection 'the fastest-rising wireless security star.'";
myTips[8]="<a href="http://www.bob .com/us/en/home/products/trials?    utm_source=community&utm_medium=dyk&utm_campaign=dyk">bob bob </a> is always up to     date and works quietly in the background and out of your way.";
myTips[9]="Need help setting up bob bob ? Check out our instructional videos on <a     href="http://www.youtube.com/playlist?list=bob ">the **bob ** YouTube channel.</a>";
myTips[10]="You can subscribe to a forum by visiting the forum, clicking 'options, and     clicking 'subscribe.'";
myTips[11]="You can subscribe to a topic by viewing the topic, clicking 'options, and clicking 'subscribe.'";
myTips[12]="Don't post your keycode in public. Sending it to a bob employee via a private message is ok, but nobody else!";
myTips[13]="You can send a user a private message by clicking on their username and then clicking 'send this user a private message.'";
myTips[14]="You can read the Community Guidelines by clicking <a href="https://community.bob .com/t5/Community-Announcements/bob -Community-Guidelines/m-    p/2#M826">here</a>. Please read them!";
myTips[15]="Notification settings are adjustable within your profile settings.";
myTips[16]="bob was founded in 1997 by the late Steven Thomas. His work is carried on today by his sister, Anna, who is a member of <a href="https://community.bob .com/t5/custom/page/page-id/meet-the-community-team">our social media team</a>.";
myTips[17]="You can <a href="http://www.bob .com/us/en/home/products/trials?    utm_source=community&utm_medium=dyk&utm_campaign=dyk">try bob for free</a> on your PC and/or     Mac. And on mobile devices, we have free offerings for both <a     href="https://play.google.com/store/apps/details?id=com.bob .security">Android</a> and <a     href="https://itunes.apple.com/us/app/bob -bob -browser/id460986853?mt=8">iOS.</a>";
myTips[18]="Are you an IT person at a business? Try <a href="http://www.bob .com/us/en/business/?sc=701F0000000dwMR&utm_source=community&utm_medium=dyk&utm_campaign=dyk">bob business solutions</a> for free. They are guaranteed to work alongside your current solution.";
myTips[19]="bob intelligence network determines over 200,000 files per day.";
myTips[20]="<a href="http://www.bob .com/customerSupport/trialRegistration.php?trpd=WSAB&loc=USA&sc=701F0000000dRvA&utm_source=community&utm_medium=rail&utm_campaign=trial">bob bob </a> will run on Citrix XenApp servers.";
myTips[21]="Each year, bob ";
myTips[22]="bob is headquartered in bob , CO but has offices all over the world.";
myTips[23]="bob won an <a href="http://www.bob.com/us/en/company/press-room/reviews-awards/?utm_source=community&utm_medium=dyk&utm_campaign=dyk">Edison Award</a> for innovation in business.";
myTips[24]="PC Magazine has awarded bob<a href="http://www.bob.com/us/en/company/press- room/reviews-awards/?utm_source=community&utm_medium=dyk&utm_campaign=dyk">'Editor’s Choice,'</a> 12 times.";
myTips[25]="bob protects over 30 million users.";
myTips[26]="Mac’s aren’t invincible. You can <a href="http://www.bob.com/us/en/home/products/mac?utm_source=community&utm_medium=dyk&utm_campaign=dyk">protect your Mac</a> with bob.";
myTips[27]="bobis <a href="http://www.bob.com/us/en/partners/?utm_source=community&utm_medium=dyk&utm_campaign=dyk">partnered with Facebook</a> to protect its users against malicious URL’s.";
myTips[28]="bobprovides the best support in the industry, bar none. We have a 95% customer satisfaction score.";
myTips[29]="bobhas a team of 10 bloggers on the <a href="http://blog.bob.com/?utm_source=community&utm_medium=dyk&utm_campaign=dyk">bobThreat Blog</a>, and we post a new blog usually at least 5 times per week.";
myTips[30]="bob has over 10,000 Twitter followers.  Follow us <a href="http://twitter.com/bob?utm_source=community&utm_medium=dyk&utm_campaign=dyk">@bob</a>! ";
var rand = Math.floor((Math.random()*29)+1);
x.innerHTML = myTips[rand]; }
</script>

At this point if you run it will will not give you any output on the page. Why??

4

4 回答 4

1

尝试这个:

x.innerHTML=myTips[Math.floor(Math.random()*3)];
于 2013-07-25T22:41:31.680 回答
1

您没有转义字符串中的双引号。要么在每个双引号前加上反斜杠,要么使用单引号来创建字符串:

'<a href="http://example.com">Example</a>';

或者:

"<a href=\"http://example.com\">Example</a>";

于 2013-07-25T22:42:14.600 回答
1

试试这个代码...

x.innerHTML = myTips[Math.floor(Math.random()*3)];
于 2013-07-25T22:43:01.490 回答
0

试试这个:

var rand = Math.floor((Math.random()*3)+1);
x.innerHTML=myTips[rand];
于 2013-07-25T22:41:28.743 回答