千家信息网

javascript经典函数使用示例

发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,这篇文章主要介绍javascript经典函数使用示例,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!1。字符串替代方法。function String_Replace(srcSt
千家信息网最后更新 2026年11月01日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{
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经典函数使用示例"这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!

右边 项目 方法 函数 示例 经典 内容 字符 字符串 对象 点数 篇文章 两个 价值 兴趣 小伙 小伙伴 整数 更多 知识 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 百单网互联网科技有限公司怎么样 科技互联网产品 鸠鸠互联网科技 广州互联网科技公司 互联网科技公司发展 猪兼强互联网科技 互联网科技公司怎么样 深圳卡尔迅互联网科技有限公司怎么样 顺网科技2021年互联网排名 中国最先进互联网科技公司 新华互联网科技2019 中国互联网有什么科技含量 河南猎农互联网科技有限公司 梅州GM互联网络科技有限公司 风投北京互联网科技 下一代互联网重大应用科技园 北京天晋互联网科技有限公司 保山浩联互联网科技有限公司 互联网科技创业有什么好项目 互联网科技快速发展优美句子 互联网科技 北京路客互联网科技有限公司 科技创新与互联网经济 互联网科技英文 互联网未来科技 兼蜜互联网科技 人人互联网科技是培训 哈尔滨秒房互联网科技有限公司 上海互联网科技园景观 安徽九吞吴互联网科技有限公司
0