打印

[軟件] java

java

有沒方法可以把紅色 變做隨機值?

1. webpage1.html
2. webpage2.html
3. webpage3.html
4. webpage4.html
5. webpage5.html

<style type="text/css">
<!--
body {
        background-image: url(wallpaper.bmp);
}
-->
</style><div align="center">
  <p> </p>
  <p> </p>
  <table width="480" border="0">
    <tr>
      <td width="480"> <script language='JavaScript'>
//7
window.open('ASIAD','menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=0,scrollbars=0,width=510,height=110');
</script> <img src="SchoolLogoA.JPG" /></a></td>
    </tr>
    <tr>
      <td><script type="text/javascript">
// Popup window code
function newPopup(url) {
        popupWindow = window.open(
                url,'popUpWindow','resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no')
}
</script>
<a href="JavaScript:newPopup('D/games/01_Cow/Dots_123.htm');"><img src="DIconA.JPG" width="480" height="214" onmouseover="this.src='DIconB.JPG';" onmouseout="this.src='DIconA.JPG';" /></a></td>
    </tr>
    <tr>
      <td><script type="text/javascript">
// Popup window code
function newPopup(url) {
        popupWindow = window.open(
                url,'popUpWindow','resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=no')
}

</script>
<a href="JavaScript:newPopup('M/games/K01-EN-01/002/Matching_Pairs.htm');"><img src="MIconA.JPG" width="480" height="214" onmouseover="this.src='MIconB.JPG';" onmouseout="this.src='MIconA.JPG';" /></a></td>
    </tr>
  </table>
</div>
第一誌願移民反大陸!
--------------------------------
誰都知道錢能生錢,我們所積累起來資產透過運作,
就能夠不斷帶來現金收入

TOP

The Random Hyperlink: How It's Done
I do not pretend to be an expert on JavaScript. I created the following code by adapting random image scripts I had seen on various webpages. It works by creating a data structure called an array, essentially a container for several different variables. In this example those variables are the text strings of your hyperlinks: the web addresses you want the random link to choose between.

The Header Code
It is convenient to initialize this array (or arrays, each corresponding to a different link on the page) in the header of the document, instead of taking up space within the <body> tag with messy code blocks. The code you need to insert is fairly straightforward, shown here in context within an HTML file:

<html>
<head>
...
<script type="text/javascript">
<!––
        link = new Array; //creates array

        link[1]="random/end1.html";
        link[2]="random/end2.html";
        link[3]="random/end3.html";
––>
</script>
<!––end1.html, etc represent the files
you wish your link to choose between––>
</head>
etcetera.Of course, "link" is a completely arbitrary name, although I personally recommend using similar names if you have a single array. Names like "link1", "link2", and so on work well if you are going to have multiple random links on a page. Simplicity is always best in computer code.

The Body Code
Once the array is initialized, you simply have to use a fragment of JavaScript in the place of your regular <a href="foo/bar.html">LinkName</a>  tag. The code for that fragment is shown below; you may remove the line breaks to condense it into one line if you prefer your code that way, as long as semicolons and less- or greater-than signs are preserved.

<script language="JavaScript">
        random_num = (math.round((Math.random()*2)+1));
        document.write(">a href=\"" + link[random_num]
                + "\">example</a>");
</script>There are a few things to note about these code fragments. First, as mentioned above, as long as the basic formatting is preserved (semicolons, etc) you may condense it into one line. The actual code for the example link in this document is
<script language="JavaScript">random_num = (Math.round((Math.random()*2)+1)); document.write("<a href=\"" + link[random_num] + "\">example</a>");</script>
For more information on how to economize your code, see this additional document.

More important than that, this code and the header code must be modified to allow choosing from a different number of links (currently choosing between three). The modification to the top part is easy: simply continue adding link[X]="foo.html"; lines, incrementing X by one each time. That change must be reflected in the random number generator, however. To modify that portion of code, you must type random_num = (math.round((Math.random()*X)+1));, where X is equal to one less than the number of elements in the array. For example, if you need the link to select one of ten arrays, replace X with 9. Do not forget that "random_num" is an arbitrary variable name, either.

The Result
In the end, the actual use of random links is up to you. It takes more effort to create a document that would be enhanced, rather than damaged, by random linking; however, the end result could well be creative and interesting in the hands of a talented writer. The tools have been laid out for you.
第一誌願移民反大陸!
--------------------------------
誰都知道錢能生錢,我們所積累起來資產透過運作,
就能夠不斷帶來現金收入

TOP

唔識

TOP

引用:
原帖由 qcmadness 於 2010-11-19 10:38 發表
唔識
見你覆左,正在入來一刻諗緊"嗯,QC真係勁,乜都識的。"

TOP

為左一個JAVASCRIPT效果 而要寫多兩組JAVASCRIPT
我就真係無咁好心機

TOP