分类 代码 下的文章

jQuery - 获取对象 object 的长度

var bookAuthors = {
    "Farmer Giles of Ham": "J.R.R. Tolkien",
    "Out of the Silent Planet": "C.S. Lewis",
    "The Place of the Lion": "Charles Williams",
    "Poetic Diction": "Owen Barfield"
};
// 获取对象的key值
var arr = Object.keys(bookAuthors);
console.log(arr);
// 获取长度
console.log(arr.length);

vue 中 filters 获取 data 里的数据

// 声明一个全局变量
let that;
// 在生命周期 beforeCreate里面改变this指向
beforeCreate: function () {
     that = this;
},
filters:{
  timeFilter(val){
      let data = that.time;
      return data;
  }
},

jquery - h5 - 长摁

代码

<!DOCTYPE html>  
<html>  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<title>h5 jquery 长摁</title>
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<style>
#mydiv {
    width: 100%;
    height: 100px; 
    background:#ddd;
    font-size: 30px;
    text-align: center;
}
</style>
</head>  
<body>  
长摁下方灰色区域
<div id="mydiv">这里是文字</div>
<script>  
$("body").delegate("#mydiv", "click", function () {
    console.log('点击');
});
var timeout;
$("body").delegate("#mydiv", "touchstart", function (e) {
    console.log('开始长摁');
    timeout = setTimeout(function () {
        $("#mydiv").text("你长摁了");  
    }, 1500);
    stopPropagation(e);
});
$("body").delegate("#mydiv", "touchmove", function (e) {
    console.log('touchmove');
    clearTimeout(timeout);
}, {passive: false});
$("body").delegate("#mydiv", "touchend", function (e) {
    console.log('touchend');
    $("#mydiv").text("这里是文字");  
    clearTimeout(timeout);
});
//阻止冒泡
function stopPropagation(e) {
    if (e.stopPropagation)
        e.stopPropagation();
    else
        e.cancelBubble = true;
}
</script>
</body>  
</html>

阅读全文