您的位置:首页 > Web前端 > JQuery

js简单显示和隐藏div,触发超链接,动态更改button值,setInterval()简单使用,jquery easyui弹出框简单使用

2015-02-04 14:23 896 查看
js简单显示和隐藏div:

myjs.html



<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
window.onload=function(){
document.getElementById("hi1").onclick = function(){
document.getElementById("d").style.display='block';
};
document.getElementById("hi2").onclick = function(){
document.getElementById("d").style.display='none';
};
}
</script>
<style type="text/css">
#d{
display: none;
color: red;
}
</style>
</head>
<body>
显示<input id="hi1" type="radio" name="hi"/>隐藏<input id="hi2" type="radio" name="hi"/>
<div id="d">这是要显示和隐藏的数据</div>
</body>
</html>


js触发超链接

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<input type="button" id="button" value="控制超链接" onclick="fun()"/>
<a href="myjs.html" id="aa">跳转到</a>
</body>
<script type="text/javascript">
function fun(){
var link = document.getElementById("aa").href;
window.location.href = link;
}
</script>
</html>

隐藏显示div,动态更改button值

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
#hi{
display: none;
}
</style>
<script type="text/javascript">
window.onload=function(){
var i=0;
document.getElementById("bu").onclick=function(){
if(i%2==0){
document.getElementById("bu").value="Click to hidden answer";
document.getElementById("hi").style.display = 'block';
}else{
document.getElementById("bu").value="Click to see the answer";
document.getElementById("hi").style.display = 'none';
}
i++;
};
};
</script>
</head>
<body>
<input type="button" id="bu" value="Click to see the answer"/>
<div id="hi">
This is the answer.
</div>
</body>
</html>

setInterval()

<html>
<head>
<script>
var ret = window.setInterval("changeTime()",50);//第二个参数以毫秒为单位
function changeTime(){
var d = new Date();
document.getElementById("changeTime").value=d.getFullYear()+"年"+(d.getMonth()+1)+"月"+d.getDate()+"日  "+d.getHours()+"时"+d.getMinutes()+"分"+d.getSeconds()+"秒";
}

</script>
</head>
<body>
<input type="text" id="changeTime" size="30"/>
</body>
</html>

jQuery easyui 弹出框

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ComboBox Actions - jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../../themes/icon.css">
<link rel="stylesheet" type="text/css" href="../demo.css">
<script type="text/javascript" src="../../jquery.min.js"></script>
<script type="text/javascript" src="../../jquery.easyui.min.js"></script>
</head>
<body>
<h2>ComboBox</h2>
<p>Click the buttons below to perform actions.</p>

<div style="margin:20px 0;">
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="setvalue()">SetValue</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="alert($('#state').combobox('getValue'))">GetValue</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#state').combobox('disable')">Disable</a>
<a href="javascript:void(0)" class="easyui-linkbutton" onclick="$('#state').combobox('enable')">Enable</a>
</div>
<script type="text/javascript">
var i ;
function setvalue(){
/*
$.messager.prompt('SetValue','Please input the value(CO,NV,UT,etc):',function(v){
if (v){
$.messager.show(
{
title: "电脑监测",
msg: "CPU温度过高,请浇凉水",
showType: 'fade',
timeout: 5000
}
);
}
});

$.messager.alert(
'这是一个警告框','cpu温度过高','warning',function(){
}
);

$.messager.confirm("删除确认","确定要删除吗?",function(data){
i=data;
alert(i);
});
*/
$.messager.prompt("输入框","请输入一个数字",function(data){
$.messager.alert("输入提示框","您输入的数字是:"+data,'info');
});
}
</script>

</body>
</html>


如果出现乱码,首先查看页面中是否设置了编码,如果页面中设置了编码uft-8,则可以用记事本打开文件,另存为,查看文件的编码是否和页面编码相同,即是否为utf-8,如果不是,则可以选择utf--8进行保存。乱码即可解决,如果还未解决,则可先以utf-8格式建立一个html文件,然后将出现乱码并且页面编码为utf-8的html内容拷贝进来,则乱码可被解决。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: