JavaScript 메소드 및 기법의 종합 모음_기본 지식
이 블로그에서는 JavaScript를 소개하고 있는데, Clang에서 봤어요. 저자의 소개는 꽤 포괄적이어서 관심 있는 친구들이 살펴볼 수 있도록 다시 게시했습니다. 하하~~
때로는 한 언어에 능숙하지만 실제로는 하루 종일 다른 언어를 다루고 있다는 것을 알게 될 것입니다. 하지만 당신이 주의를 기울이지 않는 것은 많은 시간을 낭비하게 될 것입니다. 나는 몇 년 전에 JavaScript를 마스터했다고 항상 생각했습니다. 지금까지 JavaScript를 점점 더 많이 느끼고 있습니다. 생각보다 훨씬 복잡하고 강력해서 숭배하기 시작했습니다. 모든 OOP 언어를 숭배하는 것처럼~
휴일을 활용하여 JavaScript와 관련된 방법과 기술을 정리하겠습니다. JavaScript에 대해 걱정하는 사람은 이것이 JavaScript의 전부라는 것을 이해할 것입니다! 그리고 JavaScript도 여러분의 친구가 되어 여러분이 갑자기 깨달음을 얻고 프로젝트에 더 잘 적용할 수 있기를 바랍니다~
적절한 읽기 범위: JavaScript에 대해 아무것도 모르는 사람 ~ 숙달까지 한 걸음 더
기본: HTML
자바스크립트 1: 기초
1 스크립트 블록 생성
1:
2 숨겨진 스크립트 코드
1:
JavaScript를 지원하지 않는 브라우저에서는 해당 코드가 실행되지 않습니다
3 브라우저에서 지원하지 않는 경우 , 2: JavaScript가 아닌 브라우저입니다.
3:
4 외부 스크립트 파일 연결
1:
5 댓글 스크립트
1: // 댓글입니다.
2: document .write(“Hello”) ; // 이것은 주석입니다
3: /*
4: 이 모든 것
5: 주석입니다
6: */
6 브라우저에 출력
1: document.write(“
Hello
”)
7 변수 정의
1: var myVariable = “어떤 값”;
8 문자열 추가
1: var myString = “String1” “String2”; 🎜>9 문자열 검색
1:
10 문자열 교체
1 : thisVar.replace(“월요일”,”금요일” );
11 형식 문자열
1:
12 배열 생성
1:
13 배열 정렬
1:
14 분할 문자열
1:
15 팝업 경고 메시지
1:
16 팝업 확인 상자
1:
17 함수 정의
1:
18 JS 호출 function
1:
링크 텍스트
2:
링크 텍스트
19 페이지가 완료된 후 함수 실행 로드됨
1:
2: 페이지 본문
3:
20 조건부 판단
1:
21 지정된 루프 수
1:
22 향후 실행 설정
1:
23 스케줄 실행 기능
1:
24 스케줄 실행 취소
1:
25 페이지 언로드 시 함수 실행
1:
2: 본문 페이지
3:
JavaScript 2에 대한 내용입니다: 브라우저 출력
26 문서 개체에 액세스
1:
27 HTML을 동적으로 출력
1:
28 개행 출력
1: document.writeln(“
a
”);
2: document.writeln(“b”)
29 출력 날짜
1:
30 지정된 날짜의 시간대
1:
31 날짜 출력 형식 설정
1:
32 URL 매개변수 읽기
1:
HTML이 Stateless라고 생각하시나요?
33 새 문서 개체 열기
34 페이지 이동
1:
<script> <BR>2: JavaScript code goes here <BR>3: </script><script> <BR>2: <!-- <BR>3: document.write(“Hello”); <BR>4: // --> <BR>5: </script><script></script><script> <BR>2: <!-- <BR>3: var myVariable = “Hello there”; <BR>4: var therePlace = myVariable.search(“there”); <BR>5: document.write(therePlace); <BR>6: // --> <BR>7: </script>35 웹페이지 로딩 진행창 추가 <script> <BR>2: <!-- <BR>3: var myVariable = “Hello there”; <BR>4: document.write(myVariable.big() + “<br>”); <BR>5: document.write(myVariable.blink() + “<br>”); <BR>6: document.write(myVariable.bold() + “<br>”); <BR>7: document.write(myVariable.fixed() + “<br>”); <BR>8: document.write(myVariable.fontcolor(“red”) + “<br>”); <BR>9: document.write(myVariable.fontsize(“18pt”) + “<br>”); <BR>10: document.write(myVariable.italics() + “<br>”); <BR>11: document.write(myVariable.small() + “<br>”); <BR>12: document.write(myVariable.strike() + “<br>”); <BR>13: document.write(myVariable.sub() + “<br>”); <BR>14: document.write(myVariable.sup() + “<br>”); <BR>15: document.write(myVariable.toLowerCase() + “<br>”); <BR>16: document.write(myVariable.toUpperCase() + “<br>”); <BR>17: <BR>18: var firstString = “My String”; <BR>19: var finalString = firstString.bold().toLowerCase().fontcolor(“red”); <BR>20: // --> <BR>21: </script><script> <BR>2: <!-- <BR>3: var myArray = new Array(5); <BR>4: myArray[0] = “First Entry”; <BR>5: myArray[1] = “Second Entry”; <BR>6: myArray[2] = “Third Entry”; <BR>7: myArray[3] = “Fourth Entry”; <BR>8: myArray[4] = “Fifth Entry”; <BR>9: var anotherArray = new Array(“First Entry”,”Second Entry”,”Third Entry”,”Fourth Entry”,”Fifth Entry”); <BR>10: // --> <BR>11: </script>1: <script> <BR>2: <!-- <BR>3: var myArray = new Array(5); <BR>4: myArray[0] = “z”; <BR>5: myArray[1] = “c”; <BR>6: myArray[2] = “d”; <BR>7: myArray[3] = “a”; <BR>8: myArray[4] = “q”; <BR>9: document.write(myArray.sort()); <BR>10: // --> <BR>11: </script> <script> <BR>2: <!-- <BR>3: var myVariable = “a,b,c,d”; <BR>4: var stringArray = myVariable.split(“,”); <BR>5: document.write(stringArray[0]); <BR>6: document.write(stringArray[1]); <BR>7: document.write(stringArray[2]); <BR>8: document.write(stringArray[3]); <BR>9: // --> <BR>10: </script>2: <script> <BR>2: <!-- <BR>3: window.alert(“Hello”); <BR>4: // --> <BR>5: </script> <script> <BR>2: <!-- <BR>3: var result = window.confirm(“Click OK to continue”); <BR>4: // --> <BR>5: </script>3: <script> <BR>2: <!-- <BR>3: function multiple(number1,number2) { <BR>4: var result = number1 * number2; <BR>5: return result; <BR>6: } <BR>7: // --> <BR>8: </script> <script> <BR>2: <!-- <BR>3: var userChoice = window.confirm(“Choose OK or Cancel”); <BR>4: var result = (userChoice == true) ? “OK” : “Cancel”; <BR>5: document.write(result); <BR>6: // --> <BR>7: </script>6 : <script> <BR>2: <!-- <BR>3: var myArray = new Array(3); <BR>4: myArray[0] = “Item 0”; <BR>5: myArray[1] = “Item 1”; <BR>6: myArray[2] = “Item 2”; <BR>7: for (i = 0; i < myArray.length; i++) { <BR>8: document.write(myArray[i] + “<br>”); <BR>9: } <BR>10: // --> <BR>11: </script>메인페이지<script> <BR>2: <!-- <BR>3: function hello() { <BR>4: window.alert(“Hello”); <BR>5: } <BR>6: window.setTimeout(“hello()”,5000); <BR>7: // --> <BR>8: </script> <script> <BR>2: <!-- <BR>3: function hello() { <BR>4: window.alert(“Hello”); <BR>5: window.setTimeout(“hello()”,5000); <BR>6: } <BR>7: window.setTimeout(“hello()”,5000); <BR>8: // --> <BR>9: </script>7: <script> <BR>2: <!-- <BR>3: function hello() { <BR>4: window.alert(“Hello”); <BR>5: } <BR>6: var myTimeout = window.setTimeout(“hello()”,5000); <BR>7: window.clearTimeout(myTimeout); <BR>8: // --> <BR>9: </script> <script> <BR>2: var myURL = document.URL; <BR>3: window.alert(myURL); <BR>4: </script>8: <script> <BR>2: document.write(“<p>Here's some information about this document:”); <BR>3: document.write(“<ul>”); <BR>4: document.write(“<li>Referring Document: “ + document.referrer + “”); <BR>5: document.write(“<li>Domain: “ + document.domain + “”); <BR>6: document.write(“<li>URL: “ + document.URL + “”); <BR>7: document.write(“”); <BR>8: </script> <script> <BR>2: var thisDate = new Date(); <BR>3: document.write(thisDate.toString()); <BR>4: </script>9: <script> <BR>2: var myOffset = -2; <BR>3: var currentDate = new Date(); <BR>4: var userOffset = currentDate.getTimezoneOffset()/60; <BR>5: var timeZoneDifference = userOffset - myOffset; <BR>6: currentDate.setHours(currentDate.getHours() + timeZoneDifference); <BR>7: document.write(“The time and date in Central Europe is: “ + currentDate.toLocaleString()); <BR>8: </script>메인페이지입니다<script> <BR>2: var thisDate = new Date(); <BR>3: var thisTimeString = thisDate.getHours() + “:” + thisDate.getMinutes(); <BR>4: var thisDateString = thisDate.getFullYear() + “/” + thisDate.getMonth() + “/” + thisDate.getDate(); <BR>5: document.write(thisTimeString + “ on “ + thisDateString); <BR>6: </script>10:
11:
JavaScript就这么回事3:图像
36 读取图像属性
1:

2: Width
3:
37 动态加载图像
1: <script> <BR>2: myImage = new Image; <BR>3: myImage.src = “Tellers1.jpg”; <BR>4: </script>
38 简单的图像替换
1: <script> <BR>2: rollImage = new Image; <BR>3: rollImage.src = “rollImage1.jpg”; <BR>4: defaultImage = new Image; <BR>5: defaultImage.src = “image1.jpg”; <BR>6: </script>
7: 8: onMouseOut=”document.myImage.src = defaultImage.src;”>
9:

39 随机显示图像
1: <script> <BR>2: var imageList = new Array; <BR>3: imageList[0] = “image1.jpg”; <BR>4: imageList[1] = “image2.jpg”; <BR>5: imageList[2] = “image3.jpg”; <BR>6: imageList[3] = “image4.jpg”; <BR>7: var imageChoice = Math.floor(Math.random() * imageList.length); <BR>8: document.write(‘<img src="/static/imghw/default1.png" data-src="http://img.sxsky.net/it//”image1.jpg" class="lazy" src=”' + imageList[imageChoice] + ‘“ alt="JavaScript 메소드 및 기법의 종합 모음_기본 지식" >'); <BR>9: </script>
40 函数实现的图像替换
1: <script> <BR>2: var source = 0; <BR>3: var replacement = 1; <BR>4: function createRollOver(originalImage,replacementImage) { <BR>5: var imageArray = new Array; <BR>6: imageArray[source] = new Image; <BR>7: imageArray[source].src = originalImage; <BR>8: imageArray[replacement] = new Image; <BR>9: imageArray[replacement].src = replacementImage; <BR>10: return imageArray; <BR>11: } <BR>12: var rollImage1 = createRollOver(“image1.jpg”,”rollImage1.jpg”); <BR>13: </script>
14: 15: onMouseOut=”document.myImage1.src = rollImage1[source].src;”>
16:

17:
41 创建幻灯片
1: <script> <BR>2: var imageList = new Array; <BR>3: imageList[0] = new Image; <BR>4: imageList[0].src = “image1.jpg”; <BR>5: imageList[1] = new Image; <BR>6: imageList[1].src = “image2.jpg”; <BR>7: imageList[2] = new Image; <BR>8: imageList[2].src = “image3.jpg”; <BR>9: imageList[3] = new Image; <BR>10: imageList[3].src = “image4.jpg”; <BR>11: function slideShow(imageNumber) { <BR>12: document.slideShow.src = imageList[imageNumber].src; <BR>13: imageNumber += 1; <BR>14: if (imageNumber < imageList.length) { <BR>15: window.setTimeout(“slideShow(“ + imageNumber + “)”,3000); <BR>16: } <BR>17: } <BR>18: </script>
19:
20:
21:

42 随机广告图片
1: <script> <BR>2: var imageList = new Array; <BR>3: imageList[0] = “image1.jpg”; <BR>4: imageList[1] = “image2.jpg”; <BR>5: imageList[2] = “image3.jpg”; <BR>6: imageList[3] = “image4.jpg”; <BR>7: var urlList = new Array; <BR>8: urlList[0] = “http://some.host/”; <BR>9: urlList[1] = “http://another.host/”; <BR>10: urlList[2] = “http://somewhere.else/”; <BR>11: urlList[3] = “http://right.here/”; <BR>12: var imageChoice = Math.floor(Math.random() * imageList.length); <BR>13: document.write(‘<a href=”' + urlList[imageChoice] + ‘“><img src="/static/imghw/default1.png" data-src="http://img.sxsky.net/it//”login.gif" class="lazy" src=”' + imageList[imageChoice] + ‘“ alt="JavaScript 메소드 및 기법의 종합 모음_기본 지식" >'); <BR>14: </script>
JavaScript就这么回事4:表单
还是先继续写完JS就这么回事系列吧~
43 表单构成
1:
44 访问表单中的文本框内容
1:
4: Check Text Field
45 动态复制文本框内容
1:
5: 6: document.myForm.myText.value;”>Copy Text Field
46 侦测文本框的变化
1:
47 访问选中的Select
1:
8: Check Selection List
48 动态增加Select项
1:
7: <script> <BR>8: document.myForm.mySelect.length++; <BR>9: document.myForm.mySelect.options[document.myForm.mySelect.length - 1].text = “3”; <BR>10: document.myForm.mySelect.options[document.myForm.mySelect.length - 1].value = “Third Choice”; <BR>11: </script>
49 验证表单字段
1: <script> <BR>2: function checkField(field) { <BR>3: if (field.value == “”) { <BR>4: window.alert(“You must enter a value in the field”); <BR>5: field.focus(); <BR>6: } <BR>7: } <BR>8: </script>
9:
50 验证Select项
1: function checkList(selection) {
2: if (selection.length == 0) {
3: window.alert(“You must make a selection from the list.”);
4: return false;
5: }
6: return true;
7: }
51 动态改变表单的action
1:
52 使用图像按钮
1:
6:
53 表单数据的加密
1: <script> <BR>2: <!-- <BR>3: function encrypt(item) { <BR>4: var newItem = ''; <BR>5: for (i=0; i < item.length; i++) { <BR>6: newItem += item.charCodeAt(i) + '.'; <BR>7: } <BR>8: return newItem; <BR>9: } <BR>10: function encryptForm(myForm) { <BR>11: for (i=0; i < myForm.elements.length; i++) { <BR>12: myForm.elements[i].value = encrypt(myForm.elements[i].value); <BR>13: } <BR>14: } <BR>15: <BR>16: //--> <BR>17: </script>
18:
JavaScript就这么回事5:窗口和框架
54 改变浏览器状态栏文字提示
1: <script> <BR>2: window.status = “A new status message”; <BR>3: </script>
55 弹出确认提示框
1: <script> <BR>2: var userChoice = window.confirm(“Click OK or Cancel”); <BR>3: if (userChoice) { <BR>4: document.write(“You chose OK”); <BR>5: } else { <BR>6: document.write(“You chose Cancel”); <BR>7: } <BR>8: </script>
56 提示输入
1: <script> <BR>2: var userName = window.prompt(“Please Enter Your Name”,”Enter Your Name Here”); <BR>3: document.write(“Your Name is “ + userName); <BR>4: </script>
57 打开一个新窗口
1: //打开一个名称为myNewWindow的浏览器新窗口
2: <script> <BR>3: window.open(“http://www.liu21st.com/”,”myNewWindow”); <BR>4: </script>
58 设置新窗口的大小
1: <script> <BR>2: window.open(“http://www.liu21st.com/”,”myNewWindow”,'height=300,width=300'); <BR>3: </script>
59 设置新窗口的位置
1: <script> <BR>2: window.open(“http://www.liu21st.com/”,”myNewWindow”,'height=300,width=300,left=200,screenX=200,top=100,screenY=100'); <BR>3: </script>
60 是否显示工具栏和滚动栏
1: <script> <BR>2: window.open(“http: <br><br><BR>61 是否可以缩放新窗口的大小 <br><br>1: <script language=”JavaScript”> <BR>2: window.open('http://www.liu21st.com/' , 'myNewWindow', 'resizable=yes' );</script>
62 加载一个新的文档到当前窗口
1: Open New Document
63 设置页面的滚动位置
1: <script> <BR>2: if (document.all) { //如果是IE浏览器则使用scrollTop属性 <BR>3: document.body.scrollTop = 200; <BR>4: } else { //如果是NetScape浏览器则使用pageYOffset属性 <BR>5: window.pageYOffset = 200; <BR>6: }</script>
64 在IE中打开全屏窗口
1: Open a full-screen window
65 新窗口和父窗口的操作
1: <script> <BR>2: //定义新窗口 <BR>3: var newWindow = window.open(“128a.html”,”newWindow”); <BR>4: newWindow.close(); //在父窗口中关闭打开的新窗口 <BR>5: </script>
6: 在新窗口中关闭父窗口
7: window.opener.close()
66 往新窗口中写内容
1: <script> <BR>2: var newWindow = window.open(“”,”newWindow”); <BR>3: newWindow.document.open(); <BR>4: newWindow.document.write(“This is a new window”); <BR>5: newWIndow.document.close(); <BR>6: </script>
67 加载页面到框架页面
1:
5: 在frame1中加载frame2中的页面
6: parent.frame2.document.location = “135b.html”;
68 在框架页面之间共享脚本
如果在frame1中html文件中有个脚本
1: function doAlert() {
2: window.alert(“Frame 1 is loaded”);
3: }
那么在frame2中可以如此调用该方法
1:
2: This is frame 2.
3:
69 数据公用
可以在框架页面定义数据项,使得该数据可以被多个框架中的页面公用
1: <script> <BR>2: var persistentVariable = “This is a persistent value”; <BR>3: </script>
4:
这样在frame1和frame2中都可以使用变量persistentVariable
70 框架代码库
根据以上的一些思路,我们可以使用一个隐藏的框架页面来作为整个框架集的代码库
1:

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제









JavaScript 문자열 교체 방법 및 FAQ에 대한 자세한 설명 이 기사는 JavaScript에서 문자열 문자를 대체하는 두 가지 방법 인 내부 JavaScript 코드와 웹 페이지의 내부 HTML을 탐색합니다. JavaScript 코드 내부의 문자열을 교체하십시오 가장 직접적인 방법은 대체 () 메소드를 사용하는 것입니다. str = str.replace ( "find", "replace"); 이 메소드는 첫 번째 일치 만 대체합니다. 모든 경기를 교체하려면 정규 표현식을 사용하고 전역 플래그 g를 추가하십시오. str = str.replace (/fi

그래서 여기 당신은 Ajax라는이 일에 대해 배울 준비가되어 있습니다. 그러나 정확히 무엇입니까? Ajax라는 용어는 역동적이고 대화식 웹 컨텐츠를 만드는 데 사용되는 느슨한 기술 그룹을 나타냅니다. 원래 Jesse J에 의해 만들어진 Ajax라는 용어

기사는 JavaScript 라이브러리 작성, 게시 및 유지 관리, 계획, 개발, 테스트, 문서 및 홍보 전략에 중점을 둡니다.

이 기사는 브라우저에서 JavaScript 성능을 최적화하기위한 전략에 대해 설명하고 실행 시간을 줄이고 페이지로드 속도에 미치는 영향을 최소화하는 데 중점을 둡니다.

매트릭스 영화 효과를 페이지에 가져 오십시오! 이것은 유명한 영화 "The Matrix"를 기반으로 한 멋진 jQuery 플러그인입니다. 플러그인은 영화에서 클래식 그린 캐릭터 효과를 시뮬레이션하고 사진을 선택하면 플러그인이 숫자로 채워진 매트릭스 스타일 사진으로 변환합니다. 와서 시도해보세요. 매우 흥미 롭습니다! 작동 방식 플러그인은 이미지를 캔버스에로드하고 픽셀 및 색상 값을 읽습니다. data = ctx.getImageData (x, y, settings.grainsize, settings.grainsize) .data 플러그인은 그림의 직사각형 영역을 영리하게 읽고 jQuery를 사용하여 각 영역의 평균 색상을 계산합니다. 그런 다음 사용하십시오

이 기사는 브라우저 개발자 도구를 사용하여 효과적인 JavaScript 디버깅, 중단 점 설정, 콘솔 사용 및 성능 분석에 중점을 둡니다.

이 기사에서는 jQuery 라이브러리를 사용하여 간단한 사진 회전 목마를 만들도록 안내합니다. jQuery를 기반으로 구축 된 BXSLIDER 라이브러리를 사용하고 회전 목마를 설정하기위한 많은 구성 옵션을 제공합니다. 요즘 그림 회전 목마는 웹 사이트에서 필수 기능이되었습니다. 한 사진은 천 단어보다 낫습니다! 그림 회전 목마를 사용하기로 결정한 후 다음 질문은 그것을 만드는 방법입니다. 먼저 고품질 고해상도 사진을 수집해야합니다. 다음으로 HTML과 일부 JavaScript 코드를 사용하여 사진 회전 목마를 만들어야합니다. 웹에는 다양한 방식으로 회전 목마를 만드는 데 도움이되는 라이브러리가 많이 있습니다. 오픈 소스 BXSLIDER 라이브러리를 사용할 것입니다. BXSLIDER 라이브러리는 반응 형 디자인을 지원 하므로이 라이브러리로 제작 된 회전 목마는

데이터 세트는 API 모델 및 다양한 비즈니스 프로세스를 구축하는 데 매우 필수적입니다. 그렇기 때문에 CSV 가져 오기 및 내보내기가 자주 필요한 기능인 이유입니다.이 자습서에서는 각도 내에서 CSV 파일을 다운로드하고 가져 오는 방법을 배웁니다.
