javascript经典函数用法有哪些

发布时间:2021-12-03 14:01:37 作者:小新
来源:亿速云 阅读:114

这篇文章主要为大家展示了“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;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+"不能为空&iexcl;");
 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经典函数用法有哪些”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. JavaScript的经典实现案例
  2. JavaScript callback回调函数用法实例分析

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

javascript 函数

上一篇:Java中有哪些锁

下一篇:tk.Mybatis插入数据获取Id怎么实现

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》