加载次序
.1等页面加载完毕
<script type="text/javascript">
jQuery(window).load(function(){
...
});
</script>
$(window).load(function(){...})
.2一开始加载
$(document).ready(function(){}),或简写为$(function(){})
.3在所有DOM元素加载之前执行的jQuery代码
<script type="text/javascript">
(function() {
alert("DOM还没加载哦!");
})(jQuery)
</script> . toggle函数
var myAudio = document.getElementById("myAudio");
$("#pic1").toggle(function () {
myAudio.src = "upfiles/music/01.mp3";
myAudio.play();
$("#pic1").removeClass('navout');
$("#pic1").addClass('navOn');
}, function () {
myAudio.pause();
$("#pic1").removeClass('navOn');
$("#pic1").addClass('navout');
});
.添加css
$("#creatbox, #creatboxType2").css("display", "none");
document.getElementById("btn1").className="down_btn1 font18bg"; .mouseover函数
$('.title-list li').mouseover(function(){
var liindex = $('.title-list li').index(this);
$(this).addClass('on').siblings().removeClass('on');
$('.product-wrap div.product').eq(liindex).fadeIn().siblings('div.product').hide();
var liWidth = $('.title-list li').width();
$('.lanrenzhijia .title-list p').stop(false,true).animate({'left' : liindex * liWidth + 'px'},);
}); .click函数
$(document).ready(function(){
//页面中的DOM已经装载完成时,执行的代码
$("#Mul > li > a").click(function(){
//找到主菜单项对应的子菜单项
var ulNode = $(this).next("ul");
ulNode.slideToggle();
changeIcon($(this));
});
}); 在元素上加onclick()
<a class="bootstro" onclick="SeachByBytton();" id="btnSearch">
function SeachByBytton() {
AssessmentVModel.GetData();
}
或者
<input type="button" id="btnPrint" value="Export" />
$(document).on('click', '#btnPrint', function () {
ExportToPDF($('#divtoPrint'),[], '导出标题', PDFPageType.Portrait);
});
.开关灯
$(".SoundHuaLi ul li").hover(
function () {
$(this).siblings().find(".li_bg_02").fadeIn()
},
function () {
$(this).siblings().find(".li_bg_02").fadeOut()
}
) . getElementsByTagName
var aBtn=oDiv.getElementsByTagName('input'); .元素选中状态
<script>
window.onload = function(){
var oNav = document.getElementById('nav');
var aLi = oNav.getElementsByTagName('a');
for( var i = aLi.length; i--;){
aLi[i].onclick = function(){
for( var i = aLi.length; i--;){
aLi[i].className = '';
}
this.className = 'active';
}
}
}
</script>
<script type="text/javascript">
(function() {
var radioWrap = document.getElementById("radio_wrap"),
li = radioWrap.getElementsByTagName("li");
for(var i = ; i < li.length; i++){
li[i].onclick = function() {
for(var i = ; i < li.length; i++){
li[i].className = "";
}
this.className = "checked";
}
}
})();
</script> .添加多个样式属性
var oDiv=document.getElementById('div1');
oDiv.style.width='300px';
oDiv.style.height='300px';
oDiv.style.background='green';
$(".Nav_ul_li").css({ "background-color": "", "border": "0px" });
  $(".Nav_ul_li").eq(id).css({ "background-color": "#FBD9D9", "border": "1px solid #FFF", "border-bottom": "0px" }); .让titile滚动
<script language=javascript>
var text = document.title
var timerID
function newtext() {
clearTimeout(timerID)
document.title = text.substring(, text.length) + text.substring(, )
text = document.title.substring(, text.length)
timerID = setTimeout("newtext()", )
}
$(window).load(function () { newtext() })
</script> $('div').css({ height: '200px', background: '#0094ff' });
.下拉导航
<script>
$(document).ready(function () {
$('li.nLi').mousemove(function () {
$(this).find('ul').slideDown();//you can give it a speed
});
$('li.nLi').mouseleave(function () {
$(this).find('ul').slideUp("fast");
});
});
</script> .滚动事件
$(window).scroll(function(){
if($(this).scrollTop() > ){
$('#updown').fadeIn();
$("#logowraper").hide(); } else if($(this).scrollTop() < ) {
$('#updown').fadeOut();
$("#logowraper").show();
};
}); .相对于页面固定
html中:
<script type="text/javascript">
$(".navbg").capacityFixed();
</script>
js中:
(function($){
$.fn.capacityFixed = function(options) {
var opts = $.extend({},$.fn.capacityFixed.deflunt,options);
var FixedFun = function(element) {
var top = opts.top;
element.css({
"top":top
});
$(window).scroll(function() {
var scrolls = $(this).scrollTop();
if (scrolls > top) {
if (window.XMLHttpRequest) {
element.css({
position: "fixed",
top:
});
} else {
element.css({
top: scrolls
});
}
}else {
element.css({
position: "absolute",
top: top
});
}
});
element.find(".close-ico").click(function(event){
element.remove();
event.preventDefault();
})
};
return $(this).each(function() {
FixedFun($(this));
});
};
$.fn.capacityFixed.deflunt={
right : ,//相对于页面宽度的右边定位
top:
};
})(jQuery); .固定图片的最大宽
var maxwidth = ;
$(".news_text img").each(function(){
if ($(this).width() > maxwidth) {
$(this).width(maxwidth);}
}); .判空
if(send=='' || send==undefined || send==null)
if (send.length>) .禁用右键
<script type="text/javascript">
function stop() {
return false;
}
document.oncontextmenu = stop;
document.onselectstart = stop;
document.oncopy = stop;
document.oncut = stop;
document.onpaste = stop;
</script> .密码输入框样式
<p>密<em style="padding:0 1em;"></em>码:<input name="passwd" type="password" id="passwd" class="log_txt" style="display:none" /><input name="txt_passwd" type="text" id="txt_passwd" value="默认密码:888888" class="log_txt" />
<script>
$("#txt_passwd").focus(function () {
$("#txt_passwd").hide();
$("#passwd").show();
$("#passwd").focus();
});
$("#passwd").blur(function () {
if ($("#passwd").val() == "") {
$("#txt_passwd").show();
$("#passwd").hide()
}
});
</script>
</p> .输入框选中与失去时样式
<script language="javascript" type="text/javascript">
function glb_searchTextOnfocus(obj) {
if (obj.value == '请输入您想要的作品...')
obj.value = '';
obj.style.color = '#333';
}
function glb_searchTextOnBlur(obj) {
if (obj.value == '') {
obj.value = '请输入您想要的作品...';
obj.style.color = '#98BC00';
} else {
obj.style.color = '#333';
}
}
</script>
<input name="q" type="text" class="searchkey " value="请输入您想要的作品..." onfocus="glb_searchTextOnfocus(this);" onblur="glb_searchTextOnBlur(this);" maxlength="" /> .监听回车
$(document).keydown(function(e) {
if (e.keyCode == ) {
$("#btnLogin").click();
}
}) 20点击隐藏与显示切换
.1隐藏的为选择元素只有一个同级
<script>
$(function () {
$(".showbo").each(function () {
$(this).click(function () {
if ($(this).next().css("display") == "none") {
$(this).next().css("display", "block");
} else {
$(this).next().css("display", "none");
}
});
});
})
</script>
<div class="showbo">
<a href="javascript:void(0)" title="@item.DContent.Title">
<span>@(++i)、</span>
@(new HtmlString(GetSubString(item.DContent.Title, )))
</a>
<span class="time">@item.DContent.AddDate.ToString("yyyy-MM-dd")</span>
</div>
<div class="qusans"><span class="qpre">解疑:</span>@item.DContent.Summary</div> .2隐藏的为选择元素多个同级
$(".ziyuanmingtit").each(function () {
$(this).click(function () {
if ($(this).siblings(".zyhih").css("display") == "none") {
$(this).siblings(".zyhih").css("display", "block");
} else {
$(this).siblings(".zyhih").css("display", "none");
}
});
}); <div class="ziyuanming ziyuanmingtit"><a>@item.DContent.Title</a></div>
<div class="ziyuanda">@item.DContent.AddDate.ToString("yyyy-MM-dd")</div>
<div class="zyhih">
<span class="prepre">推荐理由:</span><div class="ppcot">@item.DContent.CustomField09</div>
<span class="prepre">馆员回复:</span><div class="ppcot">@item.DContent.CustomField10</div>
</div>
. js除法四舍五入保留小数点后两位写法
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> <head><title>floatDecimal.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
//保留两位小数
//功能:将浮点数四舍五入,取小数点后2位
function toDecimal(x) {
var f = parseFloat(x);
if (isNaN(f)) {
return;
}
f = Math.round(x*)/;
return f;
}
//制保留2位小数,如:2,会在2后面补上00.即2.00
function toDecimal2(x) {
var f = parseFloat(x);
if (isNaN(f)) {
return false;
}
var f = Math.round(x*)/;
var s = f.toString();
var rs = s.indexOf('.');
if (rs < ) {
rs = s.length;
      s += '.';
}
while (s.length <= rs + ) {
s += '';
}
return s;
}
function fomatFloat(src,pos){
return Math.round(src*Math.pow(, pos))/Math.pow(, pos);
}
//四舍五入
alert("保留2位小数:" + toDecimal(3.14159267));
alert("强制保留2位小数:" + toDecimal2(3.14159267));
alert("保留2位小数:" + toDecimal(3.14559267));
alert("强制保留2位小数:" + toDecimal2(3.15159267));
alert("保留2位小数:" + fomatFloat(3.14559267, ));
alert("保留1位小数:" + fomatFloat(3.15159267, ));
//五舍六入
alert("保留2位小数:" + 1000.003.toFixed());
alert("保留1位小数:" + 1000.08.toFixed());
alert("保留1位小数:" + 1000.04.toFixed());
alert("保留1位小数:" + 1000.05.toFixed());
//科学计数
alert(3.1415.toExponential());
alert(3.1455.toExponential());
alert(3.1445.toExponential());
alert(3.1465.toExponential());
alert(3.1665.toExponential());
//精确到n位,不含n位
alert("精确到小数点第2位" + 3.1415.toPrecision());
alert("精确到小数点第3位" + 3.1465.toPrecision());
alert("精确到小数点第2位" + 3.1415.toPrecision());
alert("精确到小数点第2位" + 3.1455.toPrecision());
alert("精确到小数点第5位" + 3.141592679287.toPrecision());
</script>
</head>
<body>
This is my HTML page. <br>
</body>
</html>
.清空文本输入框的值:
function ResetValue() {
var obj = $("input");
for (var i = ; i < obj.length; i++)
{
if (obj[i].type == "text")
{
obj[i].value = "";
}
}
} 23.鼠标进入控制div展示与收缩
 $("#txtList").mouseenter(function() {
                $("#divChkList").slideDown("fast");
            });
            $("#divMulti").mouseleave(function() {
                $("#divChkList").slideUp("fast");
            });
<div id="divMulti">
                <asp:TextBox ID="txtList" runat="server" Width="100px"></asp:TextBox>
                <div id="divChkList" style="display: none; border: solid 1px #CCCCCC; position: fixed;z-index: 100; height: 160px; width: 100px; overflow-y: scroll;
                    <asp:CheckBoxList ID="chkList" runat="server" RepeatLayout="Table" RepeatDirection="Vertical">
                    </asp:CheckBoxList>
                </div>
            </div>

最新文章

  1. ios几个重要方法
  2. WPF 动画效果
  3. css3基础必回选择器全解
  4. d20161012
  5. mysql 的 find_in_set函数使用方法
  6. 快速激活JetBrains PhpStorm WebStorm系列产品
  7. JS闭包的两个使用方向
  8. SQL 获取 IDENTITY 三种方法 SCOPE_IDENTITY、IDENT_CURRENT 和 @@IDENTITY的区别
  9. Change Fragment layout on orientation change
  10. Servlet的PrintWriter out = response.getWriter()使用
  11. T4模版引擎之生成数据库实体类
  12. [HNOI2013]切糕
  13. 【Teradata SQL】日历函数查询
  14. SVM小白教程(2):拉格朗日对偶
  15. github的使用,利用git shell命令行创建仓库并上传
  16. [leetcode]股票题型123
  17. tomcat-内存溢出java.lang.OutOfMemoryErrory:PermGen space解决方法
  18. IDEA 不能显示项目里的文件结构
  19. 转:zTree高级入门:如何通过扩展节点的属性来达到是否显示节点的删除编辑等图标(按钮)
  20. Java -- Java 类集 -- 目录

热门文章

  1. CentOS 6.9下KVM虚拟机通过virt-clone克隆虚拟机(转)
  2. zk选举过程
  3. 常见Linux版本
  4. php类库安装xml simplexml
  5. android sdk下载SDK Platform失败记录
  6. 实现自动文本摘要(python,java)
  7. Maven Web项目配置Mybatis出现SqlSessionFactory错误的解决方案
  8. es安装脚本
  9. 转: 加快Android编译速度
  10. 以JPanel为基础实现一个图像框