收集整理了一些javascript 经典函数

杨迪19910414

杨迪19910414

2016-02-19 22:16

岁数大了,QQ也不闪了,微信也不响了,电话也不来了,但是图老师依旧坚持为大家推荐最精彩的内容,下面为大家精心准备的收集整理了一些javascript 经典函数,希望大家看完后能赶快学习起来。

  本人收集客户端开发经典javascript方法,希望对大家有所帮助。

  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;istr.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、求整数方法(用到浮点数取法)

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/webkaifa/)

以下是引用片段:
 function getInt(num) 
 { 
  return parseInt(getFloat(num)); 
 }

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/webkaifa/)

  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 --;
 }
}

展开更多 50%)
分享

猜你喜欢

收集整理了一些javascript 经典函数

Web开发
收集整理了一些javascript 经典函数

收集整理些有用的JAVASCRIPT小知识

Web开发
收集整理些有用的JAVASCRIPT小知识

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

一些常用的Javascript函数

Web开发
一些常用的Javascript函数

javascript操作dom的一些函数

Web开发
javascript操作dom的一些函数

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

收集整理的Logo设计欣赏(一)

平面设计 海报设计 广告设计 画报设计 签名设计 服装设计 名片设计 画册设计 版式设计 商标设计
收集整理的Logo设计欣赏(一)

收集整理的Logo设计欣赏(三)

平面设计 海报设计 广告设计 画报设计 签名设计 服装设计 名片设计 画册设计 版式设计 商标设计
收集整理的Logo设计欣赏(三)

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

Windows Server 2008 R2安装windows media player的方法

Windows Server 2008 R2安装windows media player的方法

javascript的作用域

javascript的作用域
下拉加载更多内容 ↓