Linux -Blue forest free software | Return to home page | Site Map | Search WWW | Contact Us |
Your current position : Homepage > Free Software > Technological exchanges >Application Programming


    

Blue Forest http://www.lslnet.com at 6:28 p.m. on August 22, 2006

[JS] Problems on the digital processing

I would like to have a random number.

For example, between 0-34 :

I wrote Math.round ((Math.random () ≤) %35)

But not, it will take between 0-35 to the value of the return was due to the recent round Math.round

My question is, instead of the VBS JS can take more than Lane as ASP, the only direct rounded, but not in the minority?

Ask one more question is how dynamic change button onclick

For example,
[html]
"Input type=" button "value=" button "name="_ftn1"" btn1 "onclick=" alert ( '123'), ""
"Script>btn1.onclick=" alert ( '456'); ";</script>[/html]

Do not! How to reform?

[html]<input Type= "button" value= "button" name="_ftn1" "btn1" onclick= "alert ( '123')," "
"Script>
Btn1.onclick=function aa () {alert ( '456').)
"/script>[/html]

Thank KAI3000

Will any direct way? Also, seek the answer to the first question (I would like to use the same probability of admission to a value of these 0-34)

Ah were a few that you no problem. . . .

[html]
"Script>
A function () (
Eval ( "btn1.onclick=function aa () {alert ( '456'))")
}
"/script>
First, I was, 123<br>
"Input filled="f"" btn1 "type=" button "value=" button 1 "onclick=" alert ( '123'), ""
"Aside
The point, then try one point buttons, pop? "Organization Department Holds Press Conference
"Input type=" button "value=" one button to change the onclick "name="_ftn1"" btn2 "onclick=" javascript:a (), ""
[/html]

Math.round> Math.floor
> Rounded to the nearest

Vbs the formula :
Int ((upperbound - lowerbound + 1) * Rnd + lowerbound)


JS : That
[html]
"Script>
Alert (Math.floor (Math.random () * (34-0+1) flight));
"/script>
[/html]

Oh, thank you very ~~~

Ask a basic question

Use delete (userstr[0]); After delete array elements. The original elements will become undefind, what function to form a new row in the array ah?

Re-traversal a handle about.

But there may be a good way! I do not know!

Wrong is right, but you used the above is up again? Replacement air array? ? If not!

There used to replace behind 4003rd

Thank you, the problem has been resolved, with the Benbanfa, traversing reorganization array.

Because I was reading group to random elements, a continuous indexed random numbers.

I wonder if there is a better index of the reorganization, or other ideas for solving this problem

Jimjiang
Increase the types of judgment, I do not know why this is more of this here will be added behind the two new methods (only two Test), because these two have IE5.5+ above, there is no problem in the test, the last one will be added to the function of the array aReturn. a bit puzzled, do not know why. Add to delete the latter two methods, if not a final judgment under less subject content types will
[html]
"SCRIPT LANGUAGE=" JavaScript ""
Array.prototype.combine = function () (
Var aReturn = new Array (), i=0;
For (var in this sub) (
If (typeof (this[sub])> "function") (
AReturn[i++] = this[sub];
                }
        }
Return aReturn;
}
If (!Array.prototype.pop) (
Array.prototype.pop = function () (
Var = this[this.length-1]; lastElement
This.length = Math.max (this.length-1,0);
Return lastElement;
        }
}
If (!Array.prototype.push) (
Array.prototype.push = function () (
For (var i=0;i<arguments.length;i++)
This[this.length]=arguments[i];
Return this.length;
        }
}
"/SCRIPT>
"SCRIPT LANGUAGE=" JavaScript ""
Var arret = new Array (1,2,3,4,5,6,7);
Delete arr[0];
Delete arr[3];
Delete arr[6];
Alert (arr.combine ());
"/SCRIPT>
[/html]

[B] problems version [/b]
Jimjiang array will return to the front with two on the pop () and push (), insert combine ()
IE5.5+ insert combine return array ()

[html]
"SCRIPT LANGUAGE=" JavaScript ""
Array.prototype.combine = function () (
Var aReturn = new Array (), i=0;
For (var in this sub) = this[sub]; aReturn[i++]
Return aReturn;
}
If (!Array.prototype.pop) (
Array.prototype.pop = function () (
Var = this[this.length-1]; lastElement
This.length = Math.max (this.length-1,0);
Return lastElement;
        }
}
If (!Array.prototype.push) (
Array.prototype.push = function () (
For (var i=0;i<arguments.length;i++)
This[this.length]=arguments[i];
Return this.length;
        }
}
"/SCRIPT>
"SCRIPT LANGUAGE=" JavaScript ""
Var arret = new Array (1,2,3,4,5,6,7);
Delete arr[0];
Delete arr[3];
Delete arr[6];
Alert (arr.combine ());
"/SCRIPT>
[/html]

Oh, I know. Suddenly realize that this is Array here, because Array object to the definition of the three since, in use for (var in object), the cycle is returned.

Judgment on the D : D : D :




 Privacy Policy  Copyright © 1999-2000 LSLNET.COM. All rights reserved. Blue Forest website owners. E-mail : Webmaster@lslnet.com