這篇文章主要介紹javascript經典函數使用示例,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
通化網站建設公司創(chuàng)新互聯(lián),通化網站設計制作,有大型網站制作公司豐富經驗。已為通化成百上千家提供企業(yè)網站建設服務。企業(yè)網站搭建\外貿營銷網站建設要多少錢,請找那個售后服務好的通化做網站的公司定做!
1。字符串替代方法。
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。取字符串長度方法
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。求浮點數方法
function getFloat(num)
{
var num =
parseFloat(num);
if(isNaN(num))num = 0;
return
num;
}
4。求整數方法(用到浮點數取法)
function getInt(num)
{
return
parseInt(getFloat(num));
}
5。判斷文本域對象是否惟空
function
at_checkBlank(obj,caption) {
if(String_Replace(obj.value,"
","")=="")
{
obj.select();
alert(caption+"不能為空?");
obj.focus();
return
false;
}
return true;
}
6。兩個Select對象(llist,rlist)互相操作
var
llist = fmObj.AssignedUser;//左邊已經選中項目
var rlist =
fmObj.WaitedUser;//右邊未被選中的項目
//雙擊右邊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
--;
}
//把右邊選中的加入左邊
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[j].value = llist.options[j+1].value;
llist.options[j].text
= llist.options[j+1].text;
}
llist.length --;
}
}
以上是“javascript經典函數使用示例”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
分享名稱:javascript經典函數使用示例
本文地址:http://www.rwnh.cn/article48/pcohhp.html
成都網站建設公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、網站內鏈、定制網站、外貿網站建設、品牌網站設計、企業(yè)網站制作
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)