Get the App
SLTechnology News&Howtos  ›  Development  › 

Example of using javascript Classical function

Shulou Source: shulou.com Published: 2022-06-02 09:21:43 10月03日 Update

This article mainly introduces the use of javascript classic function examples, the article is very detailed, has a certain reference value, interested friends must read it!

one. String substitution.

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)

}

two. The method of getting the length of string

Function String_GetLength (str) {

Var iMagne rtcm 0

For (iDeviso, i256) rt++

}

Return rt

}

three. Floating point method

Function getFloat (num)

{

Var num = parseFloat (num)

If (isNaN (num)) num = 0

Return num

}

four. The method of finding integers (using floating-point numbers)

Function getInt (num)

{

Return parseInt (getFloat (num))

}

five. Judge whether the text field object is empty or not

Function at_checkBlank (obj,caption) {

If (String_Replace (obj.value, ",") = ")

{

Obj.select ()

Alert (caption+ "cannot be empty")

Obj.focus ()

Return false

}

Return true

}

six. Two Select objects (llist,rlist) operate on each other

Var llist = item selected on the left side of fmObj.AssignedUser;//

Var rlist = unselected items on the right side of fmObj.WaitedUser;//

/ / double-click the item in the select on the right

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 --; } //把右边选中的加入左边 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 --; } } } //把右边所有加入左边 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 --; } } //左边select项目双击 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 --; } //把左边选中的项目加入右边 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 --; } } } //左边所有项目加入右边 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.value = llist.options.value

Llist.options [j] .text = llist.options [j + 1] .text

}

Llist.length--

}

}

These are all the contents of the article "examples of the use of javascript Classic functions". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Right project method function example classic content character string object point article two value interest guy partner integer more knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Linux MySQL Xiaomi Shulou Tech Info