JavaScript知識(shí)點(diǎn)總結(jié)

1.獲取iframe父窗口的dom節(jié)點(diǎn)

創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站建設(shè)、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的湖濱網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

parent.$("#id");
$('#父窗口中元素的id',?parent.document).事件();?

window.parent.document.getElementById("父窗口中元素的id").事件();?//js

2.獲取iframe子窗口的dom節(jié)點(diǎn)

parent.$("#iframe的id").contents().find("#iframe中控件的id").事件();
parent.$("#iframe中控件的id",document.frames("iframe的name").document).事情();

window.frames["iframe中的name值"].document.getElementById("iframe中控件的id").事件();//js

3.將JSON對(duì)象轉(zhuǎn)化為JSON字符

var?last=JSON.stringify(obj);
var?last=obj.toJSONString();

4.由JSON字符串轉(zhuǎn)換為JSON對(duì)象

var?obj?=?JSON.parse(str);
var?obj?=?str.parseJSON();

5.數(shù)組轉(zhuǎn)字符串

a.join("-");

6.字符串轉(zhuǎn)數(shù)組

a.split(",");

7.js動(dòng)態(tài)加載文件

document.write("<script?type='text/javascript'?src='"?+?new?Date().getTime()?+"'><\/script>");?//需轉(zhuǎn)義

8.字符串轉(zhuǎn)對(duì)象

var?a?=?"['dafadsf']";
var?b?=?eval('('+a+')')[0];//"['dafadsf']"?--->?'dafadsf'

9.替換replace

str.replace(new?RegExp("<","g"),'<').replace(new?RegExp(">","g"),'>');

10.刪除List對(duì)象中的某個(gè)對(duì)象

angular.forEach($scope.files,function(n,i){
????if(file.fileid?==?n.fileid){
????????$scope.files.splice(i,1);
????}
});

11.合并兩個(gè)json對(duì)象

var?first?=?[{"a":"b"}];
var?second?=?[{"a":"c","e":"sd"}];
$.merge(first,second);//[{"a":"b"},{"a":"c","e":"sd"}]

12.判斷select是否選中

//1.判斷option是否被選中
$("#id").is(":checked");//為false時(shí)是未被選中的,為true時(shí)是被選中

$("#id").attr('checked')==undefined//為false時(shí)是未被選中的,為true時(shí)是被選中

//2.獲取select選中的值
$("#mySelect?option:selected").text();

$("#mySelect").find('option:selected').text();

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

//3.獲取select選中的索引
$("#mySelect").get(0).selectedindex;

13.截取特殊字符串最后一位

var?_href?=?"/a/b/c";
var?_l?=?_href.split("/");
_l.splice(_l.length-1,1);
var?_s?=?_l.join('/');

14.判斷dom是否顯隱

$div.is(':hidden');
$div.is(':visible');
$div.css('display')?==?'none';

15.阻止瀏覽器后退

if?(window.history?&&?window.history.pushState)?{
????$(window).on('popstate',?function?()?{
????????window.history.pushState('forward',?null,?'#');
????????window.history.forward(1);
????});
}
window.history.pushState('forward',?null,?'#');?//在IE中必須得有這兩行
window.history.forward(1);

補(bǔ)充:

1).滾動(dòng)條置頂?shù)拇a

$(document).scrollTop(0);

2).后退的代碼

window.history.back();
history.go(-1);

16.js刪除iframe

parent.$("#fileImportIO").attr("src","about:blank");
document.getElementById("fileImportIO").parentNode.removeChild(document.getElementById("fileImportIO"))

17.將字符串"abcdef"轉(zhuǎn)換成"ab,cd,ef"的方法

var?reg?=?new?RegExp("(\\w{2})(?=.)",'\g');
var?str?=?"abcded";
var?a?=?str.replace(reg,'$1,');

18.好用的可以滾動(dòng)的標(biāo)簽(只支持ie)

<marquee></marquee>

19.清空file上傳的文件

$file[0].select();
$file[0].outerHTML?=?$file[0].outerHTML;//已測(cè)
//網(wǎng)上查的兩種方式
$file[0].select();?
document.selection.clear();//1

$file[0].outerHTML=obj.outerHTML;//2

20.字符串截?。ń厝〉谌齻€(gè)‘/’之后的字符串)

var?s?=?"http://localhost/services/admin/supplier/self/846050";
console.log(s.split("/").slice(3).join('/'))

21.格式化list數(shù)據(jù)的代碼

JSON.stringify(str,null,'\t');
JSON.stringify(str,null,4);?//使用四個(gè)空格縮進(jìn)

本文標(biāo)題:JavaScript知識(shí)點(diǎn)總結(jié)
文章URL:http://www.muchs.cn/article4/gehdie.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、軟件開發(fā)、建站公司、網(wǎng)站排名、靜態(tài)網(wǎng)站、ChatGPT

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站