JavaScript Classic function __ function

Source: Internet
Author: User
JavaScript Classic functions
The client develops the classic JavaScript method,1. String substitution method.
function String_replace (srcstring,findstring,replacestring) {
Return String_replaceb (srcstring, findstring, replacestring, 0);
}
function string_replaceb (expression, find, ReplaceWith, start) {
var index = Expression.indexof (find, start);
if (index = = 1)
return expression; var findlen = find.length;
var newexp = "";
Newexp = expression.substring (0, index) + (replacewith) + (expression.substring (Index+findlen)); Return String_replaceb (Newexp, Find, ReplaceWith, Index+1+findlen);
}2. Fetch string Length method
function String_getlength (str) {
var i,rt=0;
for (i=0;i<str.length;i++)
{
rt++;
if (Str.charcodeat (i) >256) rt++;
}
return RT;
} 3. Method of finding floating points
function getfloat (num)
{
var num = parsefloat (num);
if (isNaN (num)) num = 0;
return num;
} 4. To find an integer method (using floating-point numbers)
function getInt (num)
{
Return parseint (GetFloat (num));
} 5. To determine whether a text field object is empty
function At_checkblank (obj,caption) {
if (String_replace (Obj.value, "", "") = = "")
{
Obj.select ();
Alert (caption+ "cannot be empty?");
Obj.focus ();
return false;
}
return true;
} 6. Two Select objects (llist,rlist) manipulate each other
var llist = fmobj.assigneduser;//Left selected item
var rlist = Item not selected on the right side of fmobj.waiteduser;//
Double-click an item in the right select
function Assignuser () {
if (Rlist.selectedindex < 0 | | | rlist.selectedindex > Rlist.options.length) return;
var i; llist.options.length++;
Llist.options[llist.options.length-1].value = Rlist.options[rlist.selectedindex].value;
Llist.options[llist.options.length-1].text = Rlist.options[rlist.selectedindex].text; for (i = Rlist.selectedindex I < rlist.options.length-1 i + +) {
Rlist.options[i].value = Rlist.options[i+1].value;
Rlist.options[i].text = Rlist.options[i+1].text;
}
Rlist.length--;
}
Add the right side to the left.
function assignright_assignselected () {
for (var i = rlist.length-1 i >= 0; I-) {
if (rlist.options[i].selected) {
llist.options.length++;
Llist.options[llist.options.length-1].value = Rlist.options[i].value;
Llist.options[llist.options.length-1].text = Rlist.options[i].text; for (var j = i; J < Rlist.options.length-1; J + +) {
Rlist.options[j].value = Rlist.options[j+1].value;
Rlist.options[j].text = Rlist.options[j+1].text;
}
Rlist.length--;
}
}
}
All right, add to the left.
function Assignright_assignall () {
for (var i = rlist.length-1 i >= 0; I-) {
llist.options.length++;
Llist.options[llist.options.length-1].value = Rlist.options[i].value;
Llist.options[llist.options.length-1].text = Rlist.options[i].text; for (var j = i; J < Rlist.options.length-1; J + +) {
Rlist.options[j].value = Rlist.options[j+1].value;
Rlist.options[j].text = Rlist.options[j+1].text;
}
Rlist.length--;
}
}
Left Select item Double click
function Denyuser () {
if (Llist.selectedindex < 0 | | | llist.selectedindex > Llist.options.length) return;
var i;
rlist.options.length++;
Rlist.options[rlist.options.length-1].value = Llist.options[llist.selectedindex].value;
Rlist.options[rlist.options.length-1].text = Llist.options[llist.selectedindex].text;
for (i = Llist.selectedindex I < llist.options.length-1 i + +) {
Llist.options[i].value = Llist.options[i+1].value;
Llist.options[i].text = Llist.options[i+1].text;
}
Llist.length--;
}
Add the item selected on the left to the right
function assignright_denyselected () {
for (var i = llist.length-1 i >= 0; I-) {
if (llist.options[i].selected) {
rlist.options.length++;
Rlist.options[rlist.options.length-1].value = Llist.options[i].value;
Rlist.options[rlist.options.length-1].text = Llist.options[i].text;
for (j = Llist.selectedindex J < llist.options.length-1 J + +) {
Llist.options[j].value = Llist.options[j+1].value;
Llist.options[j].text = Llist.options[j+1].text;
}
Llist.length--;
}
}
}
All items on the left add to the right
function Assignright_denyall () {
for (var i = llist.length-1 i >= 0; I-) {
rlist.options.length++;
Rlist.options[rlist.options.length-1].value = Llist.options[i].value;
Rlist.options[rlist.options.length-1].text = Llist.options[i].text;
for (j = i; J < Llist.options.length-1; J + +) {
Llist.options[j].value = Llist.options[j+1].value;
Llist.options[j].text = Llist.options[j+1].text;
}
Llist.length--;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.