您的位置:首页 > 其它

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

2007-06-28 09:12 441 查看
第一种方法:
经常用到一些在客户端实现的代码,不需要与服务器交互, 这里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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: