惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Know Your Adversary
Know Your Adversary
小众软件
小众软件
L
LangChain Blog
月光博客
月光博客
博客园 - Franky
Microsoft Azure Blog
Microsoft Azure Blog
Y
Y Combinator Blog
有赞技术团队
有赞技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
MongoDB | Blog
MongoDB | Blog
Recorded Future
Recorded Future
V
Visual Studio Blog
TaoSecurity Blog
TaoSecurity Blog
S
Schneier on Security
C
Cybersecurity and Infrastructure Security Agency CISA
P
Privacy & Cybersecurity Law Blog
T
Threat Research - Cisco Blogs
D
DataBreaches.Net
L
LINUX DO - 热门话题
C
Check Point Blog
F
Fortinet All Blogs
Hugging Face - Blog
Hugging Face - Blog
The Hacker News
The Hacker News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Security Blog
Microsoft Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
V
V2EX
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
P
Proofpoint News Feed
L
Lohrmann on Cybersecurity
博客园 - 司徒正美
T
Threatpost
P
Palo Alto Networks Blog
A
About on SuperTechFans
Spread Privacy
Spread Privacy
Engineering at Meta
Engineering at Meta
N
News | PayPal Newsroom
T
Tailwind CSS Blog
The Last Watchdog
The Last Watchdog
Blog — PlanetScale
Blog — PlanetScale
A
Arctic Wolf
量子位
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
博客园 - 聂微东
Google Online Security Blog
Google Online Security Blog
Google DeepMind News
Google DeepMind News
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Vulnerabilities – Threatpost
H
Hacker News: Front Page

szhshp 的第三边境研究所

假设, AI 把我代替的那一刻真的到来 | szhshp 的第三边境研究所 小傻瓜都能懂的 AstrBot QQ 机器人集成 MCP 功能实战指南 | szhshp 的第三边境研究所 《智人之上: 从石器时代到 AI 时代的信息网络简史》阅读笔记 | szhshp 的第三边境研究所 iPadOS 26 无法设置空间场景图片壁纸的解决方法 | szhshp 的第三边境研究所 《一路云海》(终) | szhshp 的第三边境研究所 《一路云海》(四): 如何不按套路旅行 | szhshp 的第三边境研究所 《一路云海》(三): In Ya Mellow Tone | szhshp 的第三边境研究所 《一路云海》(二): 关西世博参观纪实 | szhshp 的第三边境研究所 《一路云海》(一): 新的征程 | szhshp 的第三边境研究所 2025 大阪世博会 [ 3 天前-先到先得 ] 阶段 场馆预约必中独家攻略 | szhshp 的第三边境研究所 Hackathon 随想 | szhshp 的第三边境研究所 一杯双皮奶 | szhshp 的第三边境研究所 Armbian + CasaOS + NAS 配置指南 | szhshp 的第三边境研究所 Docker 构建镜像报错: error getting credentials - err: exit status 1, out: `` | szhshp 的第三边境研究所 Disqus RIP! 论过高的维护成本如何治疗固执的坏习惯 | szhshp 的第三边境研究所 炸弹猫桌游变体规则 | szhshp 的第三边境研究所 《小岛经济学》阅读笔记 | szhshp 的第三边境研究所 《金钱心理学》阅读笔记 | szhshp 的第三边境研究所 为知笔记 RIP: 迁移剩余的笔记 | szhshp 的第三边境研究所 2025 博客第十年展望 - 再见我的过去 | szhshp 的第三边境研究所 我在独立游戏里面致敬的作品 | szhshp 的第三边境研究所 《How to make thing faster》阅读笔记 | szhshp 的第三边境研究所 《The Art of Clean Code》阅读笔记 | szhshp 的第三边境研究所 《Clean Architecture: A Craftsman Guide to Software Structure and Design》阅读笔记 | szhshp 的第三边境研究所 《How AI Works》阅读笔记 | szhshp 的第三边境研究所 游戏策划废案 - Project Uranus | szhshp 的第三边境研究所 游戏策划废案 - Project X | szhshp 的第三边境研究所 人生第一款独立游戏开发复盘 | szhshp 的第三边境研究所 Trap of Life | szhshp 的第三边境研究所 如果我用手搓了个暗物质雏形 | szhshp 的第三边境研究所 《Rust Programming Language》- EX - Cheatsheet | szhshp 的第三边境研究所 新的播放器上线了 | szhshp 的第三边境研究所 Cypress - End-to-End Testing: OKTA Authentication with MFA | szhshp 的第三边境研究所 VSC x VIM - 反正多学几个快捷键没有坏处 | szhshp 的第三边境研究所 两小时 Docker 速成 - Getting Started | szhshp 的第三边境研究所 《The Joy of Javascript》- 5 - Data | szhshp 的第三边境研究所 《The Joy of Javascript》- 4 - Meta Programming | szhshp 的第三边境研究所 《The Joy of Javascript》- 3 - ADT(Algebraic Data Type) | szhshp 的第三边境研究所 Web-Automation Testing | szhshp 的第三边境研究所 《The Joy of Javascript》- 2 - Functor/Monad | szhshp 的第三边境研究所 《The Joy of Javascript》- 1 - Object/Function | szhshp 的第三边境研究所 EvalError: Possible side-effect in debug-evaluate | szhshp 的第三边境研究所 前端 QA 工具链指南 - husky,commitlint,commitizen,eslint,typescript,express | szhshp 的第三边境研究所 效率工具 & 软件推荐 | szhshp 的第三边境研究所 站点开源 Project Titan | szhshp 的第三边境研究所 cmd/powershell-命令速查-Cheatsheet | szhshp 的第三边境研究所 Git-命令速查与相关问题解决-Cheatsheet & Troubleshooting | szhshp 的第三边境研究所 Tailwind.css not included in NextJS Production | szhshp 的第三边境研究所 Github GraphQL API - Data Integration | szhshp 的第三边境研究所 尝试 Windows Terminal + z.lua | szhshp 的第三边境研究所 StrokePlus.net - Powerful Hotkey Boost | szhshp 的第三边境研究所 优雅地 Hack 一台黑苹果 | szhshp 的第三边境研究所 一杯关东煮 | szhshp 的第三边境研究所 Gitee x PicGo 管理图床 | szhshp 的第三边境研究所 Create Your Own Redux (Typescript) | szhshp 的第三边境研究所 Getting Started: Ionic + Capacitor + React + Typescript + Android | szhshp 的第三边境研究所 GraphQL: File Upload & Troubleshooting | szhshp 的第三边境研究所 吉祥航空随心飞刷票工具循环查票工具 | szhshp 的第三边境研究所 NVM Windows Portable Installation | szhshp 的第三边境研究所 NextJS x Typescript - Integration & Troubleshooting | szhshp 的第三边境研究所 全站点升级 - Project Titan | szhshp 的第三边境研究所 AWS-EC2-常见问题解决-Troubleshooting | szhshp 的第三边境研究所 Workbox-Getting Started | szhshp 的第三边境研究所 《时间简史》阅读笔记 | szhshp 的第三边境研究所 《时间的秩序》阅读笔记 | szhshp 的第三边境研究所 ESLint-常见问题解决-Troubleshooting | szhshp 的第三边境研究所 站点索引 | szhshp 的第三边境研究所 个人知识库搭建 - Hexo 实现 Github/Coding 持续集成 | szhshp 的第三边境研究所 BMOB-常见问题解决-Troubleshooting | szhshp 的第三边境研究所 React + Typescript: 开启 HMR/Hot Loader | szhshp 的第三边境研究所 Yarn & NPM | szhshp 的第三边境研究所 ESLint: Typescript + React + TSX 集成 | szhshp 的第三边境研究所 《10101》EP15:过年 2020 | szhshp 的第三边境研究所 Cmder-Usage | szhshp 的第三边境研究所 Redux-DOM not refreshed | szhshp 的第三边境研究所 React Semantic UI-CheatSheet | szhshp 的第三边境研究所 Typescript: Getting Started | szhshp 的第三边境研究所 Flutter-Getting Started | szhshp 的第三边境研究所 Typescript: Access window object with type check | szhshp 的第三边境研究所 VSC Extension Development-Create A Code Formatter Extension | szhshp 的第三边境研究所 OneNote Extension-Main API | szhshp 的第三边境研究所 TortoiseGit Win10 Icon not showing correctly | szhshp 的第三边境研究所 Mongoose: aggregate() 方法实现聚合函数 | szhshp 的第三边境研究所 React In Depth - React 源码解析 - render() & Fiber | szhshp 的第三边境研究所 MongoDB x Mongoose: 实现类似 Join 的功能 | szhshp 的第三边境研究所 Disqus 评论框改造工程-实现 Disqus 代理的 Serverless 服务 | szhshp 的第三边境研究所 GUI, CLI, Terminal, Shell, TTY, Console, Bash | szhshp 的第三边境研究所 Jest Async Best Practise: No Nested Async | szhshp 的第三边境研究所 关系型数据库与非关系型数据库优缺点分析 | szhshp 的第三边境研究所 New Edge & Chromium Error - Package is invalid: 'CRX_VERSION_NUMBER_INVALID' | szhshp 的第三边境研究所 选择 GraphQL 的 N 个理由 | szhshp 的第三边境研究所 StrokePlus - 鼠标手势神器的代码编写技巧 | szhshp 的第三边境研究所 嗨,好久不见 | szhshp 的第三边境研究所 Vue + ElementUI 集成 Vue Router | szhshp 的第三边境研究所 IE8 - Unknown Runtime Error Using innerHTML & Ajax | szhshp 的第三边境研究所 React: Handling Events | szhshp 的第三边境研究所 React-Navigation Integration with Redux | szhshp 的第三边境研究所 React: States is tricky | szhshp 的第三边境研究所 《10101》EP14:小剧场 | szhshp 的第三边境研究所 ColdFusion - Basic - arguments in cffunction | szhshp 的第三边境研究所
JQuery-命令速查-CheatSheet | szhshp 的第三边境研究所
2016-12-31 · via szhshp 的第三边境研究所

Meta

目录

旧笔记归档

filter 和 find 的区别

现在有一个页面,里面 HTML 代码为:

<div >
<p class="rain">测试 1</p>
</div>
<div class="rain">
     <p>测试 2</p>
</div>

如果我们使用find()方法:

var result = $("div").find(".rain");
alert(result.html() ) ;

结果:

测试 1

如果使用filter()方法:

var result = $("div").filter(".rain");
alert(result .html() );

结果:

<p>测试 2</p>

结论

  • find() 会在 div 元素内寻找 class 为 rain 的元素,是对它的子集操作
  • filter() 则是筛选 div 的 class 为 rain 的元素,是对它自身集合元素筛选

submit a form in ajax success callback-AJAX 成功时回调函数中提交 Form

首先 "target": "_blank" 肯定可以打开新页面

重点在于想要添加 async: false

  $.ajax({
      url: "……",
      method: "post",
      data:{ ……},
      async: false,
      success:function(res){
          form.attr({"action": newurl, "target": "_blank"});
          form[0].submit();
      }
  });

API

async (default: true)
Type: Boolean

By default, all requests are sent asynchronously (i.e. this is set to true by default). If you need synchronous requests, set this option to false. Cross-domain requests and dataType: “jsonp” requests do not support synchronous operation. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active. As of jQuery 1.8, the use of async: false with jqXHR ($.Deferred) is deprecated; you must use the success/error/complete callback options instead of the corresponding methods of the jqXHR object such as jqXHR.done().


JQuery-Error: Form submission causing ‘Maximum call stack size exceeded’

Desc

使用form.submit();的时候没有报错但是无限循环执行 过了几秒后报错

'Maximum call stack size exceeded'

Solution

http://stackoverflow.com/questions/31379409/form-submission-causing-maximum-call-stack-size-exceeded

Replace $('#fReviewMe').submit(); with:

$('#fReviewMe')[0].submit();

calling DOM node method submit to avoid submit jQuery handler ‘loop’.


AJAX 相关

(function(v){
    $.ajax({
        url: 'index.cfm?reg_profile'
    })
    .done(function(data) {
        // data
        // you can get v here
    })
})(btn)

试了几个方法, 比如将参数放到.done()里面作为第二个参数等等都不行, 只需要建立一个闭包即可实现

.done()可以接受三个参数

function onMyUrlLoaded(data, textStatus, jqXHR) { /* function code */ };

但是无法通过第四个参数来进行传值

另一种办法:

done(function(magic) {
  return process(magic, 42);
});

或者

callWithMagic(magic => processMagic(magic, 42));

这样可以传一个 42 进去


.each()的使用

$('img[id^=CF_HELPTEXT_]').each(function(index, value){ 
   value.click(); 
});

将 Jquery obj 里面的所有元素都点击一遍


获取数据

substr 获得子字符串

stringObject.substr(start,length)
参数描述
start必需。要抽取的子串的起始下标。必须是数值。如果是负数,那么该参数声明从字符串的尾部开始算起的位置。也就是说,-1 指字符串中最后一个字符,-2 指倒数第二个字符,以此类推。
length可选。子串中的字符数。必须是数值。如果省略了该参数,那么返回从 stringObject 的开始位置到结尾的字串。

得到选中的 option 的内容

get the text value of a selected option

$( "#myselect" ).val();

If you wanted to get the string “Mr” if the first option was selected (instead of just “1”) you would do that in the following way:

<select id="myselect">
    <option value="1">Mr</option>
    <option value="2">Mrs</option>
    <option value="3">Ms</option>
    <option value="4">Dr</option>
    <option value="5">Prof</option>
</select>
 
$( "#myselect option:selected" ).text();

控件相关

select

添加 option

$('#mySelect').append($('<option>', {
    value: 1,
    text: 'My option'
}));

If you’re adding options from a collection of items, you can do the following:

$.each(items, function (i, item) {
    $('#mySelect').append($('<option>', { 
        value: item.value,
        text : item.text 
    }));
});

disable select

$("#"+arrFields[i]).prop('disabled', true);
$("#"+arrFields[i]).prop('disabled', false);

删除 select 里面所有 option

remove all the options of a select box and then add one option and select it

$('#mySelect')
    .find('option')
    .remove()
    .end()
    .append('<option value="whatever">text</option>')
    .val('whatever')
;

注意原因不明多个 remove()不能一起执行 分成两句后解决问题


Checkbox

勾选所有 Checkbox

$('input:checkbox').prop("checked", true);

注意使用的是prop()

得到 checkbox 的值

JS 方法

document.getElementById('viewDept').checked

Jquery 方法

$('id').val()
 

得到多个值并用逗号分割:

var state_array=new Array();  
$('input[type=checkbox][name=state]:checked').each(function(index, el) {
    state_array.push($(this).val());
});
var states = state_array.join(',')
 
 

选中某 Checkbox 的同时取消选择其他所有 jQuery: Uncheck other checkbox on one checked

$('input.chkbox').on('change', function() {
  if(this.checked) $('input.chkbox').not(this).prop('checked', false); 
});

判断是否被选中

JS:

document.getElementById('viewDept').checked

JQuery:

$('id').is(':checked')

注意这里使用了伪类


Toggle for editable of inputs

$('#el').prop('disabled', function(i, v) { return !v; });
$("input[type='checkbox']").is(':checked')

返回结果:选中=true,未选中=false


获取 Iframe 里面的元素 和 Jquery 操作 CSS&style

使用 Jquery 直接获取 Iframe 里面的元素是不行的 需要多一层操作

$("#portalFrameID").contents().find(".smelter-alert").css("background-color","blue");

表单

获取表单里各种值

获取值:
  文本框,文本区域:$("#txt").attr("value");
  多选框 checkbox:$("#checkbox_id").attr("value");
  单选组 radio: $("input[@type=radio][@checked]").val();
  下拉框 select: $('#sel').val();
 
  控制表单元素:
  文本框,文本区域:$("#txt").attr("value",'');//清空内容
  $("#txt").attr("value",'11');//填充内容
 
  多选框 checkbox: $("#chk1").attr("checked",'');//不打勾
  $("#chk2").attr("checked",true);//打勾
  if($("#chk1").attr('checked')==undefined) //判断是否已经打勾
 
  单选组 radio: $("input[@type=radio]").attr("checked",'2');//设置 value=2 的项目为当前选中项
  下拉框 select: $("#sel").attr("value",'-sel3');//设置 value=-sel3 的项目为当前选中项
  $("<option value='1'>1111</option><option value='2'>2222</option>").appendTo("#sel")//添加下拉框的 option
  $("#sel").empty();//清空下拉框.

JQuery 动态添加表单

var $form = $('<form method="post" action="tib.cfm?ajaxModal"></form>');
 
$form.append('<input name="index" type="hidden" value="'+$(this).data('metaresultid')+'" />')
    .append('<input name="type" type="hidden" value="excel" />')
    .appendTo('body')
    .submit();

return false;

使用 JQuery 效率比较高并且兼容性强

获取 Jquery 对象数组中的所有文字

arr = $('#mw-content-text .navbox-list .navbox-list a').map(function(i, el) {
    console.log( $(el).text());
}).get();

Jquery 对象的属性转为数组 Query select attributes into an array

var myVals = [];
$('li','ul').each(function(){
  myVals.push($(this).attr('value'));
});

页面控制

滚动到对应位置

可以对单个 Elem 进行滚动,或者对 window 进行滚动 可以滚动到对应 y 轴位置,数字作为参数,也可以滚动到对应 elem

$('#BoxModalContent').scrollTop('#BoxModalContent')

事件绑定与解绑

使用.on() bind 事件,使用.unBind() 取消 bind 事件

注意事件不会被覆盖,因此如果希望加载另一个同名事件则需要先取消加载然后重新 bind

$('#modalContinue').unbind('click').on('click', function(event) {
        /* do sth*/
});

AJAX 文件上传

注意关于附件,AJAX 仅仅能上传,下载的话需要打开一个新页面。

直接用 form.serialize() 对于文件选择的 input 无效。 因此只需要使用 FormData 这个 Object 即可解决问题

$('#upload').on('click', function(event) {
 
    var data = new FormData($("[name=excelUploadForm]")[0]);
 
    $.ajax({
        url: 'sir_distExcelUpload.cfm?type=read',
        type: 'POST',
        cache: false,
        contentType: false,
        processData: false,
        data: data
    })
        .done(function() {
        console.log("success");
    })
        .fail(function() {
        console.log("error");
    })
        .always(function() {
        console.log("complete");
    });
 
});
 

关于 attachEvent 报错

Error Msg

In IE 11: Object doesn’t support property or method ‘attachEvent’

In Chrome: window.attachEvent is not a function

Desc

attachEvent is a deprecated function used in older versions of Internet Explorer. For modern browsers use this instead.

el.addEventListener(evt,func,false);

Solution1

You could also create a function which checks which function to use

function addListener(el, event, func){
    if (el.addEventListener) {
       el.addEventListener(event, func, false);
    }
    else {
       el.attachEvent("on"+event, func);
    }
}

Then you can attach your event by doing this:

var element = document.getElementById('myElement');
addListener(element, 'click', function(){
    alert('You have clicked!');
});

Solution2

If you are unable to do this then perhaps a polyfill will work instead. Try to insert this somewhere:

if(!document.attachEvent){
  Object.prototype.attachEvent=function(event,func){
    this.addEventListener(event.split('on')[1], func);
  }
}

触发实例:

$("button#demo").click()

上面的例子将触发 id=“demo” 的 button 元素的 click 事件。

绑定实例:

$("button#demo").click(function(){$("img").hide()})
 
$('ul.scopeSelector img.plusminus').click(function(){
    //some code 
    //$(this).next().next().toggle();
});

.trigger()

Desc

Execute all handlers and behaviors attached to the matched elements for the given event type.

Syntax

.trigger( event [, extraParameters ] )

实际上就是触发已经有的 event

Examples

To pass arbitrary data to an event:

$( "p" )
  .click(function( event, a, b ) {
    // When a normal click fires, a and b are undefined
    // for a trigger like below a refers to "foo" and b refers to "bar"
  })
  .trigger( "click", [ "foo", "bar" ] );

Alternative way to pass data through an event object:

$( "body" ).trigger({
  type:"logged",
  user:"foo",
  pass:"bar"
});

.ready()

There is also $(document).on( "ready", handler ), deprecated as of jQuery 1.8

Desc

Specify a function to execute when the DOM is fully loaded.

Syntax

All three of the following syntaxes are equivalent:

$( document ).ready( handler )

$().ready( handler ) this is not recommended)

$( handler )

Arguments

  • handler
    • Type: Function()
    • A function to execute after the DOM is ready.

Example

The .ready() method is typically used with an anonymous function:

$( document ).ready(function() {
  // Handler for .ready() called.
});

Which is equivalent to calling:

$(function() {
  // Handler for .ready() called.
});

JQuery&AJAX-Get/Post

示例

// 请求 test.php 网页,传送 2 个参数,忽略返回值:

$.get("test.php", { name: "John", time: "2pm" } );
// 显示 test.php 返回值(HTML 或 XML,取决于返回值):

$.get("test.php", function(data){
  alert("Data Loaded: " + data);
});
$(document).ready(function(){
        $("#jquery").click(function(){
            $.get("result.cfm?name="+$("#INPUTLOOKUP").val(),function(result){
                $("#result").html(result);
            });
        });
    });

对应的目标处理参考:

    $.ajax({
        url:"?getdatasubset",
        method:"post",
        data:{
            dids:dids,
            cols:columns,
            colnames:colnames,
            ordr:ordr,
            count:count==undefined?10:count
        },
        success:function(res){$('#BoxModalContent').html(res);},
        error:function(xhr,etype,emsg){$('#BoxModalContent').html(emsg);}
    });

data 中带有多参数的示例

$.ajax({
        url:"?getdatasubset_XML",
        method:"post",
        data:{
            data:'<data>' + xmlStr + '</data>',
            subtitle:subtitle,
            showsum:showsum
        },
        success:function(res){$('#BoxModalContent').html(res);},
        error:function(xhr,etype,emsg){$('#BoxModalContent').html(emsg);}
    });

定义和用法

get() 方法通过远程 HTTP GET 请求载入信息。 这是一个简单的 GET 请求功能以取代复杂 $.ajax 。请求成功时可调用回调函数。如果需要在出错时执行函数,请使用 $.ajax

参数

AttrExp
url必需。规定将请求发送的哪个 URL。
data可选。规定连同请求发送到服务器的数据。
success可选。规定当请求成功时运行的函数。

额外的参数:
- success(response,status,xhr)
- response - 包含来自请求的结果数据
- status - 包含请求的状态
- xhr - 包含 XMLHttpRequest 对象

dataType可选。规定预计的服务器响应的数据类型。默认地,jQuery 将智能判断。
可能的类型:
- “xml”
- “html”
- “text”
- “script”
- “json”
- “jsonp”

JQuery-AJAX-Post-Json

var json = {a:1,b:2}
 
var c = 1;
$.ajax({
    url: 'getFormFile.cfm',
    type:'POST',
    data: { "a": JSON.stringify(json)},
    success: function(data){
        $('#getDate').html(data);
    },
    error:function( jqXHR, textStatus, errorThrown ){
        alert( "Error" + errorThrown );
    }
})

.bind()

Desc

Attach a handler to an event for the elements.

Syntax

$(selector).bind(event,data,function)

Arguments

  • event
    • 必需。规定添加到元素的一个或多个事件。
    • 由空格分隔多个事件。必须是有效的事件。
  • data
    • 可选。规定传递到函数的额外数据。
  • function
    • 必需。规定当事件发生时运行的函数。

Example

给一个 Button 绑定点击事件

$("button").bind("click",function(){
  $("p").slideToggle();
});

.on()

Syntax

$(selector).on( events [, selector ] [, data ], handler )

如果后面的 Handler 不是一个 function 变量的话,就必须写成一个匿名函数

Example

$( "#dataTable tbody tr" ).on( "click", function() {
  console.log( $( this ).text() );
});

Pass data to the event handler, which is specified here by name:

function myHandler( event ) {
  alert( event.data.foo );
}
$( "p" ).on( "click", { foo: "bar" }, myHandler );

Cancel a form submit action and prevent the event from bubbling up by returning false:

$( "form" ).on( "submit", false );

Stop submit events from bubbling without preventing form submit, using .stopPropagation().

$( "form" ).on( "submit", function( event ) {
  event.stopPropagation();
});

Use the the second argument of .trigger() to pass an array of data to the event handler

$( "div" ).on( "click", function( event, salutation, name ) {
  alert( salutation + ", " + name );
});
$( "div" ).trigger( "click", [ "Goodbye", "Jim" ] );

JQuery Simple Merge

var myArray = [1,2,3,4,5,6];
console.log(myArray.slice(-1)[0])

扩展 Jquery 的 $ 方法

!function(a){
    a.extend({
        xxx: function(arg1, arg2){
            ……
        }
    })
}(jQuery)

实际上是将 Jquery 传进去并执行了 extend 方法, 之后可以通过$.xxx(arg1, arg2)进行调用

Example

  • 目的是扩展 JQuery, 以下对 jQuery 扩展了一个方法.
    • $ 或者 jQuery 仅仅是一个 constructor, 每一个变量都是它的实例.
    • 另外 $.fn 其实是 $.prototype 的别名, 给 prototype 添加方法即是给 jQuery 扩展方法
    • 使用的时候只需要 $('xxx').tipTip(args) 即可.
(function ($) {
  $.fn.tipTip = function (options) {
    var defaults = {
      arg1: "123",
      arg2: false,
    };
    // merge arguments with default arguments
    var opts = $.extend(defaults, options);

    return this.each(function (e) {
      active_tiptip(opts);
    })

    function active_tiptip(opts) { }
    function deactive_tiptip(opts) { }
  }
}
)(jQuery);

JS triggering json file download

有几个方法, 测试有效的是 Blob 下载:

saveFile: function() {
    const data = JSON.stringify(this.arr)
    const blob = new Blob([data], {type: 'text/plain'})
    const e = document.createEvent('MouseEvents'),
    a = document.createElement('a');
    a.download = "test.json";
    a.href = window.URL.createObjectURL(blob);
    a.dataset.downloadurl = ['text/json', a.download, a.href].join(':');
    e.initEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
    a.dispatchEvent(e);
}

其他方法查看这篇文章: https://stackoverflow.com/questions/48611671/vue-js-write-json-object-to-local-file