关于jQuery的知识1.0

一,首先 基础语法

  • 美元符号定义jQuery
  • 选择符selet 查询和查找HTML元素
  • jQuery的action()执行对元素的操作

JQuery是一个快速、简洁的JavaScript框架,对JS的一些功能进行了封装,例如选择ID,className等选择器统一用$定义,06年1月发布,jQuery设计的宗旨是“write Less,Do More”,写的更少做得更多,一段时间的学习后确实如此,代码量相对于JS少了很多

$("#shanchu1").on("click", function () {
     // alert(111);
       date.splice(index, 1);
       saveDate(date); //保存数据
       load(); //重新渲染页面
  })

区别于JS的印象深的两个方面是触发事件的写法不同了,还有就是jQuery对象和JS对象是不同的,区别于此的原因是不能用jQuery对象调用JS对象的方法,同样JS对象不能调用jQuery对象,但是JS对象和jQuery对象是可以相互转换的

var abc=document.getElementById('abc');
var abc=$(abc);

其实就是又选择了一次

关于jQuery的知识手册,在菜鸟教程有很多,这里就只提一些我认为重要的和遇到的问题

  • jQuery增加四种方式,append prepend before after
    • before和after是在所选元素后边添加一行代码,而append prepend是在所选元素里边添加代码
  • jQuery的删除两种方式,remove empty
    • remove删除的是这个元素,empty是删除元素里边的内容
  • jQuery的向上遍历三种方式
    • parent() 默认向上一级。parents()默认选择所有祖先,可以在括号里填写一个祖先,则指对它选择,parentutil()括号里选择一个对他选择之下的所有元素
  • jQuery向下遍历的两种方法
    • children()默认选择向下的一个儿子元素,可以选择元素的class独特选择。find()方法,里边写*选择所有后代,写一个元素则只对选择的所有元素有效果
  • jQuery同袍同级遍历有七个三大钟
    • 1,siblings()是选择除自己外所有的同级元素改变
    • 2,next()选择同级的下一个
    • 3,,nextAll()选择除自己外,下边所有的元素
    • 4,next()选择除自己外 到括号写的同级元素前的所有元素
    • 5,6,7prev()和next一样,但是是向上遍历
  • jQuery的五种过滤遍历选择
    • first()选择首个,last()选择最后一个,eq()选择同级,自动默认当组数组,给每一个相同的元素从0开始编了序号
    • fitter()是要满足某种条件表如都有一个相同的class,not()是与之相反

如上述,遍历的方法是jQuery的一个很重哟的板块

还有伪数组和数组的区别在JS会用到很多

还可以实现增删改查的功能,四个基本功能分为

拿出来

function getDate() {
                var date = localStorage.getItem("yuanshenUp");
                if (date != null) {
                    return JSON.parse(date);
                } else {
                    return [];
                }
            }

改一下

$("#test").click(function () {
                let local = getDate();

                //添加元素 
                local.push({
                    // src: $(".tx").src,
                    "src": img.src,
                    "Name": $("#name").val(),
                    "shuxing": $("#shuxing").val()
                });
                // 保存
                saveDate(local);
                // 渲染页面
                load();
            })

改的被称为具体的事件,实现不同的增删改查

存到本地存储

function saveDate(date) {
                localStorage.setItem("yuanshenUp", JSON.stringify(date));
            }

渲染出来

function load() {
                var date = getDate();
                // console.log(date);
                // 遍历前清空数据
                $(".nei-box ul").empty();

                // 遍历数据
                $.each(date, function (i, n) {
                    // console.log(n);

                    $(".nei-box ul").prepend("<li> <img src=" + n.src + "  id=" + i + "> <i>" + n.Name + "</i></li>")

                })
            }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
/* @license * jQuery.print, version 1.3.2 * (c) Sathvik Ponangi, Doers' Guild * Licence: CC-By (http://creativecommons.org/licenses/by/3.0/) *--------------------------------------------------------------------------*/ (function ($) { "use strict"; // A nice closure for our definitions function getjQueryObject(string) { // Make string a vaild jQuery thing var jqObj = $(""); try { jqObj = $(string) .clone(); } catch (e) { jqObj = $("<span />") .html(string); } return jqObj; } function printFrame(frameWindow) { // Print the selected window/iframe var def = $.Deferred(); try { setTimeout(function () { // Fix for IE : Allow it to render the iframe frameWindow.focus(); try { // Fix for IE11 - printng the whole page instead of the iframe content if (!frameWindow.document.execCommand('print', false, null)) { // document.execCommand returns false if it failed -http://stackoverflow.com/a/21336448/937891 frameWindow.print(); } } catch (e) { frameWindow.print(); } frameWindow.close(); def.resolve(); }, 250); } catch (err) { def.reject(err); } return def; } function printContentInNewWindow(content) { // Open a new window and print selected content var w = window.open(); w.[removed](content); w.document.close(); return printFrame(w); } function isNode(o) { /* http://stackoverflow.com/a/384380/937891 */ return !!(typeof Node === "object" ? o instanceof Node : o && typeof o === "object" && typeof o.nodeType === "number" && typeof o.nodeName === "string"); } $.print = $.fn.print = function () { // Print a given set of elements var options, $this, self = this; // console.log("Printing", this, arguments); if (self instanceof $) { // Get the node if it is a jQuery object self = self.get(0); } if (isNode(self)) { // If `this` is a HTML element, i.e. for // $(selector).print() $this = $(self); if (arguments.length > 0) { options = arguments[0]; } } else { if (arguments.length > 0) { // $.print(selector,options) $this = $(arguments[0]); if (isNode($this[0])) { if (arguments.length > 1) { options = arguments[1]; } } else { // $.print(options) options = arguments[0]; $this = $("html"); } } else { // $.print() $this = $("html"); } } // Default options var defaults = { globalStyles: true, mediaPrint: false, stylesheet: null, noPrintSelector: ".no-print", iframe: true, append: null, prepend: null, manuallyCopyFormValues: true, deferred: $.Deferred() }; // Merge with user-options options = $.extend({}, defaults, (options || {})); var $styles = $(""); if (options.globalStyles) { // Apply the stlyes from the current sheet to the printed page $styles = $("style, link, meta, title"); } else if (options.mediaPrint) { // Apply the media-print stylesheet $styles = $("link[media=print]"); } if (options.stylesheet) { // Add a custom stylesheet if given $styles = $.merge($styles, $('<link rel="stylesheet" href="' + options.stylesheet + '">')); } // Create a copy of the element to print var copy = $this.clone(); // Wrap it in a span to get the HTML markup string copy = $("<span/>") .append(copy); // Remove unwanted elements copy.find(options.noPrintSelector) .remove(); // Add in the styles copy.append($styles.clone()); // Appedned content copy.append(getjQueryObject(options.append)); // Prepended content copy.prepend(getjQueryObject(options.prepend)); if (options.manuallyCopyFormValues) { // Manually copy form values into the HTML for printing user-modified input fields // http://stackoverflow.com/a/26707753 copy.find("input") .each(function () { var $field = $(this); if ($field.is("[type='radio']") || $field.is("[type='checkbox']")) { if ($field.prop("checked")) { $field.attr("checked", "checked"); } } else { $field.attr("value", $field.val()); } }); copy.find("select").each(function () { var $field = $(this); $field.find(":selected").attr("selected", "selected"); }); copy.find("textarea").each(function () { // Fix for https://github.com/DoersGuild/jQuery.print/issues/18#issuecomment-96451589 var $field = $(this); $field.text($field.val()); }); } // Get the HTML markup string var content = copy.html(); // Notify with generated markup & cloned elements - useful for logging, etc try { options.deferred.notify('generated_markup', content, copy); } catch (err) { console.warn('Error notifying deferred', err); } // Destroy the copy copy.remove(); if (options.iframe) { // Use an iframe for printing try { var $iframe = $(options.iframe + ""); var iframeCount = $iframe.length; if (iframeCount === 0) { // Create a new iFrame if none is given $iframe = $('<iframe height="0" width="0" border="0" wmode="Opaque"/>') .prependTo('body') .css({ "position": "absolute", "top": -999, "left": -999 }); } var w, wdoc; w = $iframe.get(0); w = w.contentWindow || w.contentDocument || w; wdoc = w.document || w.contentDocument || w; wdoc.open(); wdoc.write(content); wdoc.close(); printFrame(w) .done(function () { // Success setTimeout(function () { // Wait for IE if (iframeCount === 0) { // Destroy the iframe if created here $iframe.remove(); } }, 100); }) .fail(function (err) { // Use the pop-up method if iframe fails for some reason console.error("Failed to print from iframe", err); printContentInNewWindow(content); }) .always(function () { try { options.deferred.resolve(); } catch (err) { console.warn('Error notifying deferred', err); } }); } catch (e) { // Use the pop-up method if iframe fails for some reason console.error("Failed to print from iframe", e.stack, e.message); printContentInNewWindow(content) .always(function () { try { options.deferred.resolve(); } catch (err) { console.warn('Error notifying deferred', err); } }); } } else { // Use a new window for printing printContentInNewWindow(content) .always(function () { try { options.deferred.resolve(); } catch (err) { console.warn('Error notifying deferred', err); } }); } return this; }; })(jQuery);

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不之道

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值