随便写写今天一个知识点(三)

第一种方法:
经常用到一些在客户端实现的代码,不需要与服务器交互, 这里JS文件代码就起很大的作用. 下面是每个系统都会用到的选择判断.

function getChkId() {
   var arrs = window.document.getElementsByName('chkId');
   var strId = '';
   for(i = 0;i < arrs.length;i++)
       {
        if(arrs[i].checked)
       strId += strId == '' ? arrs[i].value : ',' + arrs[i].value;
      }
      return strId;
  }  

引用:  A href="javascript:openwin('550','300','Notice.aspx?action=mod&id='+getChkId())" ;

页面代码: string[] id = this.Request["id"].Split(','); 循环实现 for(int i=0; i<id.Length;i++)  

第2种方法:

function CheckAll(form)
{
for (var i=0;i<Form1.elements.length;i++)
{
 var e = Form1.elements[i];
 if (e.name != 'chkall')
   e.checked = Form1.chkall.checked;
}
}

只能输入数字在js中的正则表达式应用:

function check(e){
var num=e.value;
re=/^(([1-9]/d*/./d{1,1})|(0/./d{1,1})|([1-9]/d*))$/;
if(re.test(num))
{
//alert("正确");
}
else
{
alert("错误:只能是数字!");
e.value='';
}
}

弹出窗口公用函数:

function openwin(wW,wH,wHref,winname) {
  var xMax = screen.width, yMax = screen.height;
  var xOffset = (xMax - wW)/2, yOffset = (yMax - wH)/2;
  win = window.open(wHref,winname, 'width=' + wW + ',height=' + wH + ',top=10,left='+xOffset+',toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=yes');

3. 复制到剪贴板上的代码:

function copyUrl(head,url)
{var Body='';Body+= head;Body+='/r/n'+url;window.clipboardData.setData("Text",Body);
alert("文件《"+url+"》地址已复制到剪贴版,你可按CTRL+V系统的编辑器中粘贴图片地址即可。");
}
}

4.设置上传文件个数.

function setid()
{
  str='';
  if(!window.Form1.upcount.value)
   window.Form1.upcount.value=1;
   for(i=1;i<=window.Form1.upcount.value;i++)
     str+='文件'+i+':<input type="file" name="file'+i+'"><br>';
  window.upid.innerHTML=str+'';
}

5.HTML预览代码

//HTML预览 width=400,height=50,
function runEx(){
var priview = window.open("", "priview", "status=no,menubar=no,scrollbars=yes,resizable=yes");
priview.document.open("text/html", "replace");
priview.document.write(unescape(event.srcElement.parentElement.children[0].value));
priview.document.close();
}

6.添加下拉选定到文本框实现

//添加、编辑新闻责任编辑列表选值
function drop2text(textname,str,otype)
{
 if(otype=="modify")
 {
  var s=textname.value
  if(s=="")
  {
   textname.value=str+"/n"+s;
  }
  else
  {
  if(s.indexOf(str)==-1)
   {
    textname.value=str+"/n"+s;
  }
  }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值