有时候我们要在控制台需要jquery来做一样东西,但是无奈是页面并没有引入jquery库。
这时候我们需要手动在控制台添加自己jquery类库
var importJs=document.createElement('script') //在页面新建一个script标签
importJs.setAttribute("type","text/javascript") //给script标签增加type属性
importJs.setAttribute("src", 'http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js') //给script标签增加src属
性, url地址为cdn公共库里的
document.getElementsByTagName("head")[0].appendChild(importJs)//把importJs标签添加在页面