JSON

{ "name":"John", "age":30, "city":"New York"}

JSON.parse(json_str)

获取时间

function getTime(){
//第一种  1498627266000
var millisecond =Date.parse(new Date());
console.log(millisecond);
//第二种   1498627266558
var millisecond =(new Date()).valueOf();
console.log(millisecond);
//第三种   1498627266558
var millisecond =new Date().getTime();
console.log(millisecond); var myDate = new Date();
console.log(myDate.getFullYear()); //获取完整的年份(4位,1970-????)
console.log(myDate.getMonth()); //获取当前月份(0-11,0代表1月)
console.log(myDate.getDate()); //获取当前日(1-31)
console.log(myDate.getDay()); //获取当前星期X(0-6,0代表星期天)
console.log(myDate.getTime()); //获取当前时间(从1970.1.1开始的毫秒数)
console.log(myDate.getHours()); //获取当前小时数(0-23)
console.log(myDate.getMinutes()); //获取当前分钟数(0-59)
console.log(myDate.getSeconds()); //获取当前秒数(0-59)
console.log(myDate.getMilliseconds()); //获取当前毫秒数(0-999)
console.log(myDate.toLocaleDateString()); //获取当前日期
console.log(myDate.toLocaleTimeString()); //获取当前时间
console.log(myDate.toLocaleString()); //获取日期与时间
}

reading

MDN web docs

jquery

选择器

html 标签选择

$('div')

class 选择器

$('.class_name')

id 选择器

$('#id_name')

fetch

About the Request.mode'no-cors' (from MDN, emphasis mine)

Prevents the method from being anything other than HEAD, GET or POST. If any ServiceWorkers intercept these requests, they may not add or override any headers except for these. In addition, JavaScript may not access any properties of the resulting Response. This ensures that ServiceWorkers do not affect the semantics of the Web and prevents security and privacy issues arising from leaking data across domains.

So this will enable the request, but will make the Response as opaque, i.e, you won't be able to get anything from it, except knowing that the target is there.

Since you are trying to fetch a cross-origin domain, nothing much to do than a proxy routing.

var quizUrl = 'http://www.lipsum.com/';
fetch(quizUrl, {
mode: 'no-cors',
method: 'get'
}).then(function(response) {
console.log(response.type)
}).catch(function(err) {
console.log(err) // this won't trigger because there is no actual error
});

Notice you're dealing with a Response object. You need to basically read the response stream with Response.json() or Response.text() (or via other methods) in order to see your data. Otherwise your response body will always appear as a locked readable stream.

fetch('https://api.ipify.org?format=json')
.then(response=>response.json())
.then‌​(data=>{ console.log(data); })

If this gives you unexpected results, you may want to inspect your response with Postman.


fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: login,
password: password,
})
})
.then(function (a) {
return a.json(); // call the json method on the response to get JSON
})
.then(function (json) {
console.log(json)
})

Creating a div element in jQuery


div = $("<div>").html("Loading......");
$("body").prepend(div);

$('#parent').append('<div>hello</div>');
// or
$('<div>hello</div>').appendTo('#parent');

jQuery('<div/>', {
id: 'some-id',
class: 'some-class',
title: 'now this div has a title!'
}).appendTo('#mySelector');

jQuery(document.createElement("h1")).text("My H1 Text");

<div id="targetDIV" style="border: 1px solid Red">
This text is surrounded by a DIV tag whose id is "targetDIV".
</div> //Way 1: appendTo()
<script type="text/javascript">
$("<div>hello stackoverflow users</div>").appendTo("#targetDIV"); //appendTo: Append at inside bottom
</script> //Way 2: prependTo()
<script type="text/javascript">
$("<div>Hello, Stack Overflow users</div>").prependTo("#targetDIV"); //prependTo: Append at inside top
</script> //Way 3: html()
<script type="text/javascript">
$("#targetDIV").html("<div>Hello, Stack Overflow users</div>"); //.html(): Clean HTML inside and append
</script> //Way 4: append()
<script type="text/javascript">
$("#targetDIV").append("<div>Hello, Stack Overflow users</div>"); //Same as appendTo
</script>

动态添加表格行

var $row = $('<tr>'+
'<td>'+obj.Message+'</td>'+
'<td>'+obj.Error+'</td>'+
'<td>'+obj.Detail+'</td>'+
'</tr>');
if(obj.Type=='Error') {
$row.append('<td>'+ obj.ErrorCode+'</td>');
}
$('table> tbody:last').append($row);

javascript callback的更多相关文章

  1. javascript callback函数的理解与使用

    最近做的一个项目中用到了callback函数,于是就研究了下总结下我对javascript callback的理解 首先从callback的字面翻译“回调” 可以理解这是一个函数被调用的机制 当我们遇 ...

  2. JavaScript Callback 回调函数

    JavaScript callback回调函数 你到一个商店买东西,刚好你要的东西没有货,于是你在店员那里留下了你的电话,过了几天店里有货了,店员就打了你的电话,然后你接到电话后就到店里去取了货.在这 ...

  3. Understand JavaScript Callback Functions and Use Them

    In JavaScript, functions are first-class objects; that is, functions are of the type Object and they ...

  4. JavaScript——callback(回调函数

    1.回调函数定义 回调函数就是一个通过函数指针调用的函数.如果你把函数的指针(地址)作为参数传递给另一个函数,当这个指针被用为调用它所指向的函数时,我们就说这是回调函数.回调函数不是由该函数的实现方直 ...

  5. [前端JS学习笔记]JavaScript CallBack

    一.概念介绍 CallBack : "回调" . 在spring优秀框架回调无处不在, 回调的运用场景很多, 如 swt事件监听.netty等.它的主要作用是提高程序执行效率, 一 ...

  6. 【repost】javascript callback

    在javascript中回调函数非常重要,它们几乎无处不在.像其他更加传统的编程语言都有回调函数概念,但是非常奇怪的是,完完整整谈论回调函数的在线教程比较少,倒是有一堆关于call()和apply() ...

  7. JavaScript callback function 回调函数的理解

    来源于:http://mao.li/javascript/javascript-callback-function/ 看到segmentfault上的这个问题 JavaScript 回调函数怎么理解, ...

  8. 玩转JavaScript Callback函数

    如果你对Jquery没有足够的经验,但是你又用过JQuery,这么来说没你已经用过了回调函数了.但是你可能不知道它是如何工作和实现的. 这篇文章主要基于我所了解的回调函数,我试图启发大家基于最常规的J ...

  9. JavaScript callback function 理解

    看到segmentfault上的这个问题 JavaScript 回调函数怎么理解,觉得大家把异步和回调的概念混淆在一起了.做了回答: 我觉得大家有点把回调(callback)和异步(asynchron ...

随机推荐

  1. Python类中的装饰器在当前类中的声明与调用

    [本文出自天外归云的博客园] 我的Python环境:3.7 在Python类里声明一个装饰器,并在这个类里调用这个装饰器.代码如下: class Test(): xx = False def __in ...

  2. 【java】[文件上传jar包]commons-fileUpload组件解决文件上传(文件名)乱码问题

    response.setContentType("text/html; charset=UTF-8");  Boolean isMultipart = ServletFileUpl ...

  3. 【iCore4 双核心板_ARM】例程三十二:UART_IAP_ARM实验——更新升级STM32

    实验现象及操作说明: 1.本例程共有两个代码包,APP和IAP,IAP程序功能实现将APP程序升级至STM32中. 2.直接上电或烧写程序将执行升级的APP应用程序. BIN升级文件产生方法: 1.编 ...

  4. [微信小程序] 认识微信小程序及开发环境搭建

    微信公众平台首页 https://mp.weixin.qq.com 微信公众平台测试帐号系统 https://open.weixin.qq.com/connect/qrconnect?appid=wx ...

  5. Java窗体居中显示的2种方法

    第1种方法: //setSize(300, 200); pack(); // 得到显示器屏幕的宽.高 int width = Toolkit.getDefaultToolkit().getScreen ...

  6. 《FPGA全程进阶---实战演练》第三十二章 Signal Tap II 应用实例

    还有几天就要交文章终稿了,三年的研究生生活也快要结束了,时间飞快,岁月如梭,但学习技术的热情仍然不能松懈,不懂的东西太多,需要实时保持奋斗!!过些天会继续更新<FPGA全程进阶---实战演练&g ...

  7. 使用 maven 自动将源码打包并发布

    1.maven-source-plugin 访问地址 在 pom.xml 中添加 下面的 内容,可以 使用 maven 生成 jar 的同时 生成 sources 包 <plugin> & ...

  8. ajax跨域,这应该是最全的解决方案了

    前言 从刚接触前端开发起,跨域这个词就一直以很高的频率在身边重复出现,一直到现在,已经调试过N个跨域相关的问题了,16年时也整理过一篇相关文章,但是感觉还是差了点什么,于是现在重新梳理了一下. 个人见 ...

  9. The processing instruction target matching &quot;[xX][mM][lL]&quot; is not allowed.

    现象: ERROR   : The processing instruction target matching "[xX][mM][lL]" is not allowed.  异 ...

  10. Python sqlite3操作笔记

    创建数据库 def create_tables(dbname): conn = sqlite3.connect(dbname) print "Opened database successf ...