2022-05-21 JQuery长按事件 JQuery长按事件 $(".text").on({ touchstart: function(e) { var oSpan = e.currentTarget.lastElementChild // 长按事件触发 timeOutEvent = setTimeout(function() { timeOutEvent = 0; console.log('你长按了'); }, 500); }, touchmove: function() { clearTimeout(timeOutEvent); timeOutEvent = 0; }, touchend: function() { clearTimeout(timeOutEvent); if (timeOutEvent != 0) { console.log('你点击了'); ... 2022年05月21日 885 阅读 0 评论
2021-07-30 jQuery ajax如何同步请求 jQuery ajax如何同步请求 由于$.post() 和 $.get() 默认是 异步请求,如果需要同步请求,则可以进行如下使用:在$.post()前把ajax设置为同步:$.ajaxSettings.async = false; 在$.post()后把ajax改回为异步:$.ajaxSettings.async = true; 如:$.ajaxSettings.async = false; $.post("/finance/getLastTimeCard", data, function(result) { // 请求处理 },"json"); $.ajaxSettings.async = true; $.ajax设置同步,加个async: false就可以了$.ajax({ type:"post", url:"login.php", data:{name:"name",password:"password"}, datatype: "jso... 2021年07月30日 1,141 阅读 0 评论
2021-06-05 判断页面中是否引用jQuery或者其他的 判断页面中是否引用jQuery或者其他的 必须是放在jQuery后面才能判断!第一种:<script>!window.jQuery && document.write("<script src=\"js/jquery.min.js\"><\/script>");</script> 第二种:<script>if(typeof jQuery == 'undefined'){document.write("<script src=\"js/jquery.min.js\"><\/script>");}</script> 2021年06月05日 816 阅读 0 评论
2021-05-19 jQuery获取上级、同级、下级元素 jQuery获取上级、同级、下级元素 jQuery.parent(expr) 找父亲节点,可以传入expr进行过滤,比如$("span").parent()或者$("span").parent(".class")jQuery.parents(expr),类似于jQuery.parents(expr),但是是查找所有祖先元素,不限于父元素jQuery.children(expr).返回所有子节点,这个方法只会返回直接的孩子节点,不会返回所有的子孙节点jQuery.contents(),返回下面的所有内容,包括节点和文本。这个方法和children()的区别就在于,包括空白文本,也会被作为一个jQuery对象返回,children()则只会返回节点jQuery.prev(),返回上一个兄弟节点,不是所有的兄弟节点jQuery.prevAll(),返回所有之前的兄弟节点jQuery.next(),返回下一个兄弟节点,不是所有的兄弟节点jQuery.nextAll(),返回所有之后的兄弟节点jQuery.siblings(),返回兄弟姐妹节点,不分前后jQuery.find(expr),跟jQuery.f... 2021年05月19日 835 阅读 0 评论
2021-05-14 使用jQuery播放/暂停 HTML5视频 使用jQuery播放/暂停 HTML5视频 js中的play()是不行的,play并不是jQuery的函数,而是DOM元素的函数播放$('video').trigger('play'); 暂停$('video').trigger('pause'); 点击视频播放和暂停$('video').click(function() { if ($(this).hasClass('pause')) { $("video").trigger("play"); $(this).removeClass('pause'); $(this ).addClass('play'); } else { $("video").trigger("pause"); $(this ).removeClass('play'); $(this ).addClass('pause'); ... 2021年05月14日 780 阅读 0 评论
2021-05-14 jQuery实现页面到滚动到指定位置执行某些操作 jQuery实现页面到滚动到指定位置执行某些操作 如果页面滚动到class名为group-pic的元素的位置时开始加载$(function(){ var a,b,c; a = $(window).height(); //浏览器窗口高度 var group = $(".group-pic"); $(window).scroll(function(){ b = $(this).scrollTop(); //页面滚动的高度 c = group.offset().top; //元素距离文档(document)顶部的高度 if(a+b>c){ }else{ } }); }); 点击按钮页面滚动后,按钮始终在下方var height = $(document).height() - $(window).height(); if(!($(document).scrollTop() >= height)){ var h ... 2021年05月14日 913 阅读 0 评论
2020-12-24 JQuery获取append后的动态元素 JQuery获取append后的动态元素 jquery 1.7之前用$('.btn').live('click', function() { alert('获取到了'); }); jquery 1.7+之后用on代替live,on()方法在被选元素及子元素上添加一个或多个事件处理程序$('body').on('click', '.btn', function() { alert('获取到了'); }); 2020年12月24日 785 阅读 0 评论
2020-12-05 PHP利用TXT文本存储数据 PHP利用TXT文本存储数据 1.php<?php header('content-type: application/json;charset=utf-8'); $wj = '1.txt'; if (!empty($_POST)) { //插入内容,不加FILE_APPEND,默认值为替换内容 $fp = file_put_contents($wj, $_POST['te'] . "\n", FILE_APPEND); if ($fp !== false) { echo json_encode(array('code' => '200', 'msg' => '提交成功')); } else { echo json_encode(array('code' => '400', 'msg' => '提交失败')); } } else { if (isset($_GET['te']) && $_GET['te'] == 'hq') { //获取内容 ... 2020年12月05日 995 阅读 0 评论
2020-11-18 PHP连接数据库,通过接受post请求实现增删改查 PHP连接数据库,通过接受post请求实现增删改查 1.html文件:<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="Cache-Control" content="no-cache"> <title>PHP连接数据库实现增删改查</title> </head> <body> <div> <input type="text" name="daiHao" placeholder="代号"> <input type="text" name="keMu" placeholder="科目"... 2020年11月18日 734 阅读 0 评论
2020-10-09 JQuery添加兄弟节点、相邻元素 JQuery添加兄弟节点、相邻元素 1、在每个匹配的元素之后插入内容。$("p").after("<b>Hello</b>"); 2、在每个匹配的元素之前插入内容。$("p").before("<b>Hello</b>"); 3、把所有匹配的元素插入到另一个、指定的元素元素集合的后面$("p").insertAfter("#foo"); 4、把所有匹配的元素插入到另一个、指定的元素元素集合的前面。$("p").insertBefore("#foo"); 2020年10月09日 1,303 阅读 0 评论