
Web代码片段
大大大大大桃子
这个作者很懒,什么都没留下…
展开
-
JS实时获取界面大小
$(function(){ $(window).resize(function(){ var height = $(window).height(); var width = $(window).width(); console.info("窗口宽度:" + width + "; 窗口高度:" + height)原创 2016-12-14 17:43:50 · 1830 阅读 · 0 评论 -
JavaScript 将 JSON 字符串转换成 JSON 对象的数组
JavaScript 将 JSON 字符串转换成 JSON 对象的数组: var str = '{"id":1,"name":"Test1"},{"id":2,"name":"Test2"}';var jsonObject = $.parseJSON('[' + str + ']');原创 2017-06-14 18:09:51 · 564 阅读 · 0 评论 -
JavaScript 判断元素为空(null, undefined, NaN,empty string (""),0,false)
if( value ) {}会判断以下情况: * null * undefined * NaN * empty string (“”) * 0 * false 以上情况包含所有的JavaScript的falsy值.单独判断某种情况的话可以用typeofif( typeof foo !== 'undefined' ) { // foo 为undefined}原创 2017-05-10 23:40:55 · 6960 阅读 · 0 评论 -
AngularJS 添加Click事件
AngularJS 为元素添加Click事件<i ng-click="exportData(date.id,date.title)"></i>原创 2017-04-14 15:50:47 · 5217 阅读 · 0 评论 -
JavaScript 对象转字符串(object to JSON string)
JavaScript 对象转字符串(object to JSON string)var j={"name":"soindy"};JSON.stringify(j); // '{"name":"soindy"}'原创 2017-04-14 15:11:13 · 2005 阅读 · 0 评论 -
JavaScript 获取数组的最后一个元素
index取值args[args.length - 1]pop方法args.pop()注意: pop方法会删除args最后一个元素,并返回原创 2017-04-14 11:35:12 · 130449 阅读 · 0 评论 -
JavaScript 字符串replace()和replayAll()
JavaScript 的replace()方法只会替换一处,想要全部替换的话需要加/g参数.单处替换var str = "2017-04-17";str.replace(/-/,"")console.log(str);此时打印出来为"201704-17"可见只替换了一处替换所有var str = "2017-04-17";str.replace(/-/g,"")console.log(str原创 2017-04-17 19:08:20 · 1475 阅读 · 0 评论 -
JavaScript设置form, textarea, text input元素的value
原文地址: How to set the value of a form element using Javascript设置form的值获取form对象oFormObject = document.forms['form_id'];获取单独的元素oformElement = oFormObject.elements[index];或者oFormElement = oFormObject.elem翻译 2017-01-06 23:05:15 · 4067 阅读 · 0 评论 -
CSS 设置a标签的下划线颜色(a tag underline)
设置a标签的下划线只能通过border-bottom进行设置.a{ text-decoration: none; border-bottom: 1px solid red; }原创 2016-12-29 16:16:11 · 29578 阅读 · 0 评论 -
window.onresize或者$(window).resize()触发两次
场景window.onresize或者$(window).resize()触发两次.比如浏览器全屏显示,如果使用screen.availHeight重布局屏幕会闪两次,因为resize方法会进2次.而且每次screen.availHeight都不一样.原因和浏览器的自身实现有关系.不同的浏览器和操作系统实现可能不一样,具体自己可以去玩一下. 参考: stackoverflow错误实现代码win原创 2016-12-26 16:05:07 · 15576 阅读 · 0 评论 -
设置HTML全屏时的背景色
html{ background: red;} 注意: 设置body的background在全屏效果是无效的原创 2016-12-23 15:27:30 · 6095 阅读 · 0 评论 -
JavaScript获取浏览器的回车事件(兼容所有浏览器)
<script> document.onkeydown = function(e) { var login = (typeof event != 'undefined') ? window.event: e; if(login.keyCode == 13) { // do something } };</scr原创 2017-01-03 15:23:33 · 802 阅读 · 0 评论 -
JavaScript 判断被点击li的ID和index
JavaScript 判断被点击li的ID和index:$("ul > li").click(function () { var index = $(this).prevAll().length; console.info(this.id, index); } 注: 这里的index和数组的index不一样,从1开始而不是从0.原创 2016-12-21 16:28:04 · 2222 阅读 · 0 评论 -
CSS 去掉按钮选中时的蓝色外边框
input,button,a { outline:0 none !important; blr:expression(this.onFocus=this.blur());}原创 2016-12-08 17:34:37 · 18459 阅读 · 2 评论 -
HTML 界面之间共享数据
HTML 界面之间共享数据: // 存储keyvar loginDataStoreKey = 'App.loginDataStoreKey';// 存储 window.sessionStorage.setItem(loginDataStoreKey, jsonData);// 读取var tempData = window.sessionS原创 2017-06-14 18:19:25 · 6970 阅读 · 0 评论