免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 774 | 回复: 0
打印 上一主题 下一主题

javascript 经典函数 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-03-04 17:32 |只看该作者 |倒序浏览

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;i256)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  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 = 0; i --) {
  if(rlist.options.selected) {
   llist.options.length++;
   llist.options[llist.options.length-1].value = rlist.options.value;
   llist.options[llist.options.length-1].text = rlist.options.text;
   for(var j = i; j = 0; i --) {
  llist.options.length++;
  llist.options[llist.options.length-1].value = rlist.options.value;
  llist.options[llist.options.length-1].text = rlist.options.text;
  for(var j = i; j  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 = 0; i --) {
  if(llist.options.selected) {
   rlist.options.length++;
   rlist.options[rlist.options.length-1].value = llist.options.value;
   rlist.options[rlist.options.length-1].text = llist.options.text;
   for(j = llist.selectedIndex; j = 0; i --) {
  rlist.options.length++;
  rlist.options[rlist.options.length-1].value = llist.options.value;
  rlist.options[rlist.options.length-1].text = llist.options.text;
  for(j = i; j

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/60586/showart_489365.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP