1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
根据不同浏览器: <script type="text/javascript"> var version = navigator.userAgent; if (version.indexOf("MSIE") > 1) { document.write("<link href='ie.css' rel='stylesheet' type='text\/css'\/>"); } else if (version.indexOf("Chrome") > 1) { document.write("<link href='chrome.css' rel='stylesheet' type='text\/css'\/>"); } else if (version.indexOf("Firefox") > 1) { document.write("<link href='ff.css' rel='stylesheet' type='text\/css'\/>"); } </script> 根据不同分辨率: <script type="text/javascript"> if (screen.width == 1024){ document.write("<link href='css/css1.css' rel='stylesheet' type='text\/css'\/>"); }else { document.write("<link href='css/css2.css' rel='stylesheet' type='text\/css'\/>");} </script> |
分类:前端
为 placeholder 自定义样式
关于HTML5在动画制作工具Animatron的一些问题
在HTML中禁止文字的复制
JS返回上一页
当一个页面出现多个checkbox全选时的处理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
HTML: <input type="checkbox" onclick="boxOnclick(this,'some1')">全选一 <input type="checkbox" onclick="boxOnclick(this,'some2')">全选二 <input type="checkbox" onclick="boxOnclick(this,'some3')">全选三 <input type="checkbox" class="some1">全选一的子集 <input type="checkbox" class="some2">全选二的子集 <input type="checkbox" class="some3">全选三的子集 JS: function boxOnclick(obj, someNum) { if (obj.checked) { $("." + someNum).each(function () { this.checked = true; }); } else { $("." + someNum).each(function () { this.checked = false; }); } } |
JS获取浏览器高度 并赋值给类
1 2 3 4 5 6 7 8 9 10 11 12 |
var w = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; var h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; 如果你需要给某个div设置全屏的话,可以用下面的jQuery来获取设备高度,然后赋值给类。 $(window).load(function () { var maxHeight = 0; if (document.documentElement.clientHeight > maxHeight) { maxHeight = document.documentElement.clientHeight; } $('.you-class').css("height", maxHeight) }); |
点击按钮对两个div的隐藏与显示进行切换
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
HTML: <button type="button" id="showHidden">点击切换div的隐藏与显示</button> <div id="div1">请叫我第一层</div> <div id="div2">请叫我第二层</div> JS: <script type='text/javascript'> function show_hidden(obj) { if(obj.style.diaplay == 'block') { obj.style.display = 'none'; } else { obj.style.display = 'block'; } } var sh = document.getElementById("showHidden"); sh.click = function() { var div1 = document.getElementById("div1"); var div2 = document.getElementById("div2"); show_hidden(div1); show_hidden(div2); return false; } </script> 示例: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <button type="button" id="showHidden">点击切换div的隐藏与显示</button> <div id="div1" style="display:block">请叫我第一层</div> <div id="div2" style="display:none">请叫我第二层</div> <script type='text/javascript'> function show_hidden(obj) { if(obj.style.display == 'block') { obj.style.display = 'none'; } else { obj.style.display = 'block'; } } var sh = document.getElementById("showHidden"); sh.onclick = function() { var div1 = document.getElementById("div1"); var div2 = document.getElementById("div2"); show_hidden(div1); show_hidden(div2); return false; } </script> </body> </html> |
隐藏 < input type="file" > 实现点击div或图片打开文件选择路径
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
<strong>HTML:</strong> <input type="file" style="display:none" id="addfile-btn"> <div onclick="addfile()">点击上传图片</div> <strong>JS:</strong> <script> function addfile() { document.getElementById("addfile-btn").click(); } </scrip> <strong>如果一个页面需要多个这种事件的话,显然用ID是不太好的,那么就可以通过jQuery的prev来实现同级class查找,以此实现上传控件的调用。</strong> <strong>HTML:</strong> <input type="file" style="display:none" class="addfile-btn"> <div class="upload">点击上传图片1</div> <div class="upload">点击上传图片2</div> <strong>JS:</strong> <script> $(".upload").bind('click', function() { $(this).prev(".addfile-btn").click(); }); </script> |
CSS3混合模式background-blend-mode
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<strong>注意:background属性中的背景图片和颜色混合,只能在一个background属性中。</strong> 属性值: background-blend-mode: normal; //正常 background-blend-mode: multiply; //正片叠底 background-blend-mode: screen; //滤色 background-blend-mode: overlay; //叠加 background-blend-mode: darken; //变暗 background-blend-mode: lighten; //变亮 background-blend-mode: color-dodge; //颜色减淡 background-blend-mode: color-burn; //颜色加深 background-blend-mode: hard-light; //强光 background-blend-mode: soft-light; //柔光 background-blend-mode: difference; //差值 background-blend-mode: exclusion; //排除 background-blend-mode: hue; //色相 background-blend-mode: saturation; //饱和度 background-blend-mode: color; //颜色 background-blend-mode: luminosity; //亮度 background-blend-mode: initial; //初始 background-blend-mode: inherit; //继承 background-blend-mode: unset; //复原 |