08-05
17
javascript技巧总结
作者:Java伴侣 日期:2008-05-17
1.删除提示
1)<a href="#" onclick="return(confirm('删除后无法恢复,您确定删除吗?'))">删除</a>
2)JS
<a href="#" >删除</a>
<script language="JavaScript" type="text/javascript">
function delete_confirm(){
if(event.srcElement.outerText=="删除" || event.srcElement.value=="删除")
event.returnValue=confirm("删除后将不能恢复,您确认执行删除操作么?");
}
document.onclick=delete_confirm;
</script>
2.点击按钮探出提示
<input type=button value="reload" onclick="javascript:reload()">
<script type="text/javascript">
function reload() {
if (confirm("确认?"))
{
var url="#";
window.location.href=url;
}
}
3.点击链接弹出提示
<a href="确认后的连接地址" onclick="return(confirm('想要的提示信息?'))">显示信息</a>
4.onchange()用法
<select name="year" onchange="javascript:changeYear()">
<OPTION OPTION>
</Select>
<SCRIPT language="javascript">
function changeYear(){
var url = ....;
window.location.href = url;
}
</SCRIPT>
4.根据选择的radio转向不同的URL
<input type="Radio" name="id" value="1" checked></td>
<input type="Radio" name="id" value="2" checked></td>
<input type="Radio" name="id" value="3" checked></td>
<SCRIPT language="javascript">
function WhichOneisChecked(obj) {
for (var i = 0;i < obj.elements.length;i++){
if (obj.elements[i].checked == true){
var weekLogId=obj.elements[i].value;
var url="......";
window.location.href = url;
}
}
}
</SCRIPT>
5.radio 全选
function checkAll(e, itemName)
{
var aa = document.getElementsByName(itemName);
for (var i=0; i<aa.length; i++)
aa[i].checked = e.checked;
}
function check(e, allName)
{
var all = document.getElementsByName(allName)[0];
if(!e.checked) all.checked = false;
else
{
var aa = document.getElementsByName(e.name);
for (var i=0; i<aa.length; i++)
if(!aa[i].checked) return;
all.checked = true;
}
<input type=checkbox checked name=allTeams onclick="checkAll(this, 'teamIds')">
<input type="checkbox" name="teamIds" checked value="<%=.....%>" onclick="check(this, 'allTeams')">
6.显示、隐藏
链接实现
<script language="javascript">
function showLay(divId){
var objDiv = eval(divId);
if (objDiv.style.display=="none"){
eval("sp"+divId+".innerHTML='隐藏'");
objDiv.style.display="";
}else{
eval("sp"+divId+".innerHTML='查看'");
objDiv.style.display="none";
}}
</script>
<td>
<a href="#" onclick="showLay('Layer1')"><span id="spLayer1">查看</span></a>
<br>
<div id="Layer1" style="display:none;">......</div>
</td>
按钮实现
<SCRIPT LANGUAGE="JavaScript">
function hidden_show()
{
var obj = document.getElementById("Layer1");
if(obj.style.visibility == "")
obj.style.visibility = "hidden";
else
obj.style.visibility = "";
}
</SCRIPT>
<td>
<INPUT TYPE="button" onclick="hidden_show();" value="hidden/show">
<br>
<div id="Layer1" >
<%=weekPlan%>
</div>
</td>
1)<a href="#" onclick="return(confirm('删除后无法恢复,您确定删除吗?'))">删除</a>
2)JS
<a href="#" >删除</a>
<script language="JavaScript" type="text/javascript">
function delete_confirm(){
if(event.srcElement.outerText=="删除" || event.srcElement.value=="删除")
event.returnValue=confirm("删除后将不能恢复,您确认执行删除操作么?");
}
document.onclick=delete_confirm;
</script>
2.点击按钮探出提示
<input type=button value="reload" onclick="javascript:reload()">
<script type="text/javascript">
function reload() {
if (confirm("确认?"))
{
var url="#";
window.location.href=url;
}
}
3.点击链接弹出提示
<a href="确认后的连接地址" onclick="return(confirm('想要的提示信息?'))">显示信息</a>
4.onchange()用法
<select name="year" onchange="javascript:changeYear()">
<OPTION OPTION>
</Select>
<SCRIPT language="javascript">
function changeYear(){
var url = ....;
window.location.href = url;
}
</SCRIPT>
4.根据选择的radio转向不同的URL
<input type="Radio" name="id" value="1" checked></td>
<input type="Radio" name="id" value="2" checked></td>
<input type="Radio" name="id" value="3" checked></td>
<SCRIPT language="javascript">
function WhichOneisChecked(obj) {
for (var i = 0;i < obj.elements.length;i++){
if (obj.elements[i].checked == true){
var weekLogId=obj.elements[i].value;
var url="......";
window.location.href = url;
}
}
}
</SCRIPT>
5.radio 全选
function checkAll(e, itemName)
{
var aa = document.getElementsByName(itemName);
for (var i=0; i<aa.length; i++)
aa[i].checked = e.checked;
}
function check(e, allName)
{
var all = document.getElementsByName(allName)[0];
if(!e.checked) all.checked = false;
else
{
var aa = document.getElementsByName(e.name);
for (var i=0; i<aa.length; i++)
if(!aa[i].checked) return;
all.checked = true;
}
<input type=checkbox checked name=allTeams onclick="checkAll(this, 'teamIds')">
<input type="checkbox" name="teamIds" checked value="<%=.....%>" onclick="check(this, 'allTeams')">
6.显示、隐藏
链接实现
<script language="javascript">
function showLay(divId){
var objDiv = eval(divId);
if (objDiv.style.display=="none"){
eval("sp"+divId+".innerHTML='隐藏'");
objDiv.style.display="";
}else{
eval("sp"+divId+".innerHTML='查看'");
objDiv.style.display="none";
}}
</script>
<td>
<a href="#" onclick="showLay('Layer1')"><span id="spLayer1">查看</span></a>
<br>
<div id="Layer1" style="display:none;">......</div>
</td>
按钮实现
<SCRIPT LANGUAGE="JavaScript">
function hidden_show()
{
var obj = document.getElementById("Layer1");
if(obj.style.visibility == "")
obj.style.visibility = "hidden";
else
obj.style.visibility = "";
}
</SCRIPT>
<td>
<INPUT TYPE="button" onclick="hidden_show();" value="hidden/show">
<br>
<div id="Layer1" >
<%=weekPlan%>
</div>
</td>
评论: 0 | 引用: 0 | 查看次数: 405
发表评论