当前位置: 代码迷 >> JavaScript >> js的一些容易应用
  详细解决方案

js的一些容易应用

热度:214   发布时间:2012-10-16 09:57:37.0
js的一些简单应用

1.当双击页面的时候 页面下滑.
function initialize()
{
timer=setInterval("scrollwindow()",10);
}
document.ondblclick=initialize

2.js判断是否为数字....
function number(){
var rest=document.getElementById("rt").value;
var patrn=/^\d*$/;
if(!patrn.test(rest)){
alert("半角数字のみ");
return false;
}else{
return true;
}
}

3.单击一个超链接全部选中在点击一次全不选中,当全部不选中的时候让按钮灰掉。。。
function selectAll(){
//获取所有的checkbox框
var checkList=document.getElementsByName("select");
//当第一个checkbox没有被勾中的时候,然后勾中所有的 ..
if(!document.getElementById("check").checked){
?? for(var i=0;i<checkList.length;i++){
????????? checkList[i].checked=1;
}????
?????????????? //让按钮1和按钮2可以点击
???????????????? $("#btn1").attr("disabled",false);
$("#btn2").attr("disabled",false);

}else{
??? //反之当第一个勾中了,就让他所有的全部不勾中
???? for(var i=0;i<checkList.length;i++){
????????????? checkList[i].checked=0;
????????????????
}
?????????? //让按钮1和按钮2无法点击
???????????????? $("#btn1").attr("disabled",false);
$("#btn2").attr("disabled",false);

}

}



<input id="btn1" class="btn" type="button" style="font-size: 9pt; margin-top: 25px; margin-left: 90px;"? onclick="changeColor();"??? value="按钮1" >
<input id="btn2"? class="btn" type="button"? onclick="valueCheck();" style="font-size: 9pt; margin-left: 90px;"? value="按钮2"? >

<input type="checkbox" value="${s.sySagyoYmd };${s.syStaffCd};${s.syStaffName};${s.belongShop};${s.syUkeoiGenkan};${s.syNezyogeNo};${s.tenCd}"?
name="selected" id="controlAll${m.index}"? checked="checked" onclick="grey();">


5:防止在其他窗口弹出

<script type="text/javascript">
?????? window.name = "curWindow";
</script>

<form? action="" method="post" target="curWindow">


6.jquery的一些应用:


$(‘.money.:checked’).val();
其中money是下面class属性的值;而checked是被选中的值
此时返回的是被选中的单选按钮的值;


var money=$('.money:checked').val();

<li style="padding-left: 7px;">

<input type="radio" value="30" name="quantity" class="money"/>
30元
<input type="radio" value="50" name="quantity"? class="money" />
50元
<input type="radio" value="100" name="quantity"? class="money"/>
100元
<input type="radio" value="300" name="quantity"? class="money"/>
300元
</li>


$('.error').hide();
其中error是下面的error属性,用jquery设置下面span的隐藏属性!
可以使下面的span隐藏下来;

<span class="error">电话号码必须为数值</span>

?

3 js关闭当前页面

?

function closeWin(){?

var browserName=navigator.appName;

if (browserName=="Netscape") {?

window.open('','_parent',''); window.close();?

} else if (browserName=="Microsoft Internet Explorer") {?

window.opener = "whocares"; window.close();

}

}?

?

?

4.js实现点击下载:

?

JavaScript实现点击按钮下载

??? <script type="text/javascript"">

?????????? //第一种
?? ??? ??? ?function downFile() {
?? ??? ??? ??? ?var url = "http://localhost/tst/ya.rar";
?? ??? ??? ??? ?location.href = url;
?? ??? ??? ?}

???????? //第二种

????????? function downFile() {
?? ??? ??? ??? ?var url = "http://localhost/tst/ya.rar";
?? ??? ??? ???? window.open(url);
?? ??? ??? ?}
?? ??? ?</script>
?? ??? ?<a href="http://localhost/tst/ya.rar">下载</a>
?? ??? ?<input type="button" value="下载" onclick="downFile()">

?

  相关解决方案