목차
Highlights
Named capture
Singleline (s) and extended (x) modes
The code
웹 프론트엔드 JS 튜토리얼 XRegExp 0.2: 이제 Capture_jsObject 지향이라는 이름이 붙었습니다.

XRegExp 0.2: 이제 Capture_jsObject 지향이라는 이름이 붙었습니다.

May 16, 2016 pm 07:07 PM
CAPTURE with

Update: A beta version of XRegExp 0.3 is now available as part of the RegexPal download package.

JavaScript's regular expression flavor doesn't support named capture. Well, says who? XRegExp 0.2 brings named capture support, along with several other new features. But first of all, if you haven't seen the previous version, make sure to check out my post on XRegExp 0.1, because not all of the documentation is repeated below.

Highlights

  • Comprehensive named capture support (New)
  • Supports regex literals through the <font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">addFlags</font> method (New)
  • Free-spacing and comments mode (<font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">x</font>)
  • Dot matches all mode (<font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">s</font>)
  • Several other minor improvements over v0.1

Named capture

There are several different syntaxes in the wild for named capture. I've compiled the following table based on my understanding of the regex support of the libraries in question. XRegExp's syntax is included at the top.

Library Capture Backreference In replacement Stored at
XRegExp <font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">(<name>…)</font> <font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">\k<name></font> <font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">${name}</font> <font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">result.name</font>
.NET <font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">(?<name>…)</font>
<font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">(?'name'…)</font>
<font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">\k<name></font>
<font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">\k'name'</font>
<font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">${name}</font> <font size="2"><font style="BACKGROUND-COLOR: #f5f5ff" color="#000088">Matcher.<wbr>Groups('name')</wbr></font></font>
Perl 5.10 (beta) <font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">(?<name>…)</font>
<font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">(?'name'…)</font>
<font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">\k<name></font>
<font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">\k'name'</font>
<font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">\g{name}</font>
<font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">$+{name}</font> ??
Python <nobr><font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">(?P<name>…)</font></nobr> <font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">(?P=name)</font> <font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">\g<name></font> <font size="2"><font style="BACKGROUND-COLOR: #f5f5ff" color="#000088">result.<wbr>group('name')</wbr></font></font>
PHP preg (PCRE) (.NET, Perl, and Python styles) <font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">$regs['name']</font> <font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">$result['name']</font>

No other major regex library currently supports named capture, although the JGsoft engine (used by products like RegexBuddy) supports both .NET and Python syntax. XRegExp does not use a question mark at the beginning of a named capturing group because that would prevent it from being used in regex literals (JavaScript would immediately throw an "invalid quantifier" error).

XRegExp supports named capture on an on-request basis. You can add named capture support to any regex though the use of the new "<font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">k</font>" flag. This is done for compatibility reasons and to ensure that regex compilation time remains as fast as possible in all situations.

Following are several examples of using named capture:

<SPAN class=comment><FONT color=#238b23>// Add named capture support using the XRegExp constructor</FONT></SPAN>
var repeatedWords = new XRegExp("\\b (<word> \\w+ ) \\s+ \\k<word> \\b", "gixk");

<SPAN class=comment><FONT color=#238b23>// Add named capture support using RegExp, after overriding the native constructor</FONT></SPAN>
XRegExp.overrideNative();
var repeatedWords = new RegExp("\\b (<word> \\w+ ) \\s+ \\k<word> \\b", "gixk");

<SPAN class=comment><FONT color=#238b23>// Add named capture support to a regex literal</FONT></SPAN>
var repeatedWords = /\b (<word> \w+ ) \s+ \k<word> \b/.addFlags("gixk");

var data = "The the test data.";

<SPAN class=comment><FONT color=#238b23>// Check if data contains repeated words</FONT></SPAN>
var hasDuplicates = repeatedWords.test(data);
<SPAN class=comment><FONT color=#238b23>// hasDuplicates: true</FONT></SPAN>

<SPAN class=comment><FONT color=#238b23>// Use the regex to remove repeated words</FONT></SPAN>
var output = data.replace(repeatedWords, "${word}");
<SPAN class=comment><FONT color=#238b23>// output: "The test data."</FONT></SPAN>
로그인 후 복사

In the above code, I've also used the <FONT style="BACKGROUND-COLOR: #f5f5ff" color=#000088 size=2>x</FONT> flag provided by XRegExp, to improve readability. Note that the <FONT style="BACKGROUND-COLOR: #f5f5ff" color=#000088 size=2>addFlags</FONT> method can be called multiple times on the same regex (e.g., <FONT style="BACKGROUND-COLOR: #f5f5ff" color=#000088 size=2>/pattern/g.addFlags("k").addFlags("s")</FONT>), but I'd recommend adding all flags in one shot, for efficiency.

Here are a few more examples of using named capture, with an overly simplistic URL-matching regex (for comprehensive URL parsing, see parseUri):

var url = "http://microsoft.com/path/to/file?q=1";
var urlParser = new XRegExp("^(<protocol>[^:/?]+)://(<host>[^/?]*)(<path>[^?]*)\\?(<query>.*)", "k");
var parts = urlParser.exec(url);
<SPAN class=comment><FONT color=#238b23>/* The result:
parts.protocol: "http"
parts.host: "microsoft.com"
parts.path: "/path/to/file"
parts.query: "q=1" */</FONT></SPAN>

<SPAN class=comment><FONT color=#238b23>// Named backreferences are also available in replace() callback functions as properties of the first argument</FONT></SPAN>
var newUrl = url.replace(urlParser, function(match){
	return match.replace(match.host, "yahoo.com");
});
<SPAN class=comment><FONT color=#238b23>// newUrl: "http://yahoo.com/path/to/file?q=1"</FONT></SPAN>

로그인 후 복사

Note that XRegExp's named capture functionality does not support deprecated JavaScript features including the <FONT style="BACKGROUND-COLOR: #f5f5ff" color=#000088 size=2>lastMatch</FONT> property of the global <FONT style="BACKGROUND-COLOR: #f5f5ff" color=#000088 size=2>RegExp</FONT> object and the <FONT style="BACKGROUND-COLOR: #f5f5ff" color=#000088 size=2>RegExp.prototype.compile()</FONT> method.

Singleline (s) and extended (x) modes

The other non-native flags XRegExp supports are <FONT style="BACKGROUND-COLOR: #f5f5ff" color=#000088 size=2>s</FONT> (singleline) for "dot matches all" mode, and <FONT style="BACKGROUND-COLOR: #f5f5ff" color=#000088 size=2>x</FONT> (extended) for "free-spacing and comments" mode. For full details about these modifiers, see the FAQ in my XRegExp 0.1 post. However, one difference from the previous version is that XRegExp 0.2, when using the <FONT style="BACKGROUND-COLOR: #f5f5ff" color=#000088 size=2>x</FONT> flag, now allows whitespace between a regex token and its quantifier (quantifiers are, e.g., <FONT style="BACKGROUND-COLOR: #f5f5ff" color=#000088 size=2>+</FONT>, <FONT style="BACKGROUND-COLOR: #f5f5ff" color=#000088 size=2>*?</FONT>, or <FONT style="BACKGROUND-COLOR: #f5f5ff" color=#000088 size=2>{1,3}</FONT>). Although the previous version's handling/limitation in this regard was documented, it was atypical compared to other regex libraries. This has been fixed.

The code

<SPAN class=comment><FONT color=#238b23>/* XRegExp 0.2.2; MIT License
By Steven Levithan <http://stevenlevithan.com>
----------
Adds support for the following regular expression features:
- Free-spacing and comments ("x" flag)
- Dot matches all ("s" flag)
- Named capture ("k" flag)
 - Capture: (<name>...)
 - Backreference: \k<name>
 - In replacement: ${name}
 - Stored at: result.name
*/</FONT></SPAN>

<SPAN class=comment><FONT color=#238b23>/* Protect this from running more than once, which would break its references to native functions */</FONT></SPAN>
if (window.XRegExp === undefined) {
	var XRegExp;
	
	(function () {
		var native = {
			RegExp: RegExp,
			exec: RegExp.prototype.exec,
			match: String.prototype.match,
			replace: String.prototype.replace
		};
		
		XRegExp = function (pattern, flags) {
			return native.RegExp(pattern).addFlags(flags);
		};
		
		RegExp.prototype.addFlags = function (flags) {
			var pattern = this.source,
				useNamedCapture = false,
				re = XRegExp._re;
			
			flags = (flags || "") + native.replace.call(this.toString(), /^[\S\s]+\//, "");
			
			if (flags.indexOf("x") > -1) {
				pattern = native.replace.call(pattern, re.extended, function ($0, $1, $2) {
					return $1 ? ($2 ? $2 : "(?:)") : $0;
				});
			}
			
			if (flags.indexOf("k") > -1) {
				var captureNames = [];
				pattern = native.replace.call(pattern, re.capturingGroup, function ($0, $1) {
					if (/^\((?!\?)/.test($0)) {
						if ($1) useNamedCapture = true;
						captureNames.push($1 || null);
						return "(";
					} else {
						return $0;
					}
				});
				if (useNamedCapture) {
					<SPAN class=comment><FONT color=#238b23>/* Replace named with numbered backreferences */</FONT></SPAN>
					pattern = native.replace.call(pattern, re.namedBackreference, function ($0, $1, $2) {
						var index = $1 ? captureNames.indexOf($1) : -1;
						return index > -1 ? "\\" + (index + 1).toString() + ($2 ? "(?:)" + $2 : "") : $0;
					});
				}
			}
			
			<SPAN class=comment><FONT color=#238b23>/* If "]" is the leading character in a character class, replace it with "\]" for consistent
			cross-browser handling. This is needed to maintain correctness without the aid of browser sniffing
			when constructing the regexes which deal with character classes. They treat a leading "]" within a
			character class as a non-terminating, literal character, which is consistent with IE, .NET, Perl,
			PCRE, Python, Ruby, JGsoft, and most other regex engines. */</FONT></SPAN>
			pattern = native.replace.call(pattern, re.characterClass, function ($0, $1) {
				<SPAN class=comment><FONT color=#238b23>/* This second regex is only run when a leading "]" exists in the character class */</FONT></SPAN>
				return $1 ? native.replace.call($0, /^(\[\^?)]/, "$1\\]") : $0;
			});
			
			if (flags.indexOf("s") > -1) {
				pattern = native.replace.call(pattern, re.singleline, function ($0) {
					return $0 === "." ? "[\\S\\s]" : $0;
				});
			}
			
			var regex = native.RegExp(pattern, native.replace.call(flags, /[sxk]+/g, ""));
			
			if (useNamedCapture) {
				regex._captureNames = captureNames;
			<SPAN class=comment><FONT color=#238b23>/* Preserve capture names if adding flags to a regex which has already run through addFlags("k") */</FONT></SPAN>
			} else if (this._captureNames) {
				regex._captureNames = this._captureNames.valueOf();
			}
			
			return regex;
		};
		
		String.prototype.replace = function (search, replacement) {
			<SPAN class=comment><FONT color=#238b23>/* If search is not a regex which uses named capturing groups, just run the native replace method */</FONT></SPAN>
			if (!(search instanceof native.RegExp && search._captureNames)) {
				return native.replace.apply(this, arguments);
			}
			
			if (typeof replacement === "function") {
				return native.replace.call(this, search, function () {
					<SPAN class=comment><FONT color=#238b23>/* Convert arguments[0] from a string primitive to a string object which can store properties */</FONT></SPAN>
					arguments[0] = new String(arguments[0]);
					<SPAN class=comment><FONT color=#238b23>/* Store named backreferences on the first argument before calling replacement */</FONT></SPAN>
					for (var i = 0; i < search._captureNames.length; i++) {
						if (search._captureNames[i]) arguments[0][search._captureNames[i]] = arguments[i + 1];
					}
					return replacement.apply(window, arguments);
				});
			} else {
				return native.replace.call(this, search, function () {
					var args = arguments;
					return native.replace.call(replacement, XRegExp._re.replacementVariable, function ($0, $1, $2) {
						<SPAN class=comment><FONT color=#238b23>/* Numbered backreference or special variable */</FONT></SPAN>
						if ($1) {
							switch ($1) {
								case "$": return "$";
								case "&": return args[0];
								case "`": return args[args.length - 1].substring(0, args[args.length - 2]);
								case "'": return args[args.length - 1].substring(args[args.length - 2] + args[0].length);
								<SPAN class=comment><FONT color=#238b23>/* Numbered backreference */</FONT></SPAN>
								default:
									<SPAN class=comment><FONT color=#238b23>/* What does "$10" mean?
									- Backreference 10, if at least 10 capturing groups exist
									- Backreference 1 followed by "0", if at least one capturing group exists
									- Else, it's the string "$10" */</FONT></SPAN>
									var literalNumbers = "";
									$1 = +$1; <SPAN class=comment><FONT color=#238b23>/* Cheap type-conversion */</FONT></SPAN>
									while ($1 > search._captureNames.length) {
										literalNumbers = $1.toString().match(/\d$/)[0] + literalNumbers;
										$1 = Math.floor($1 / 10); <SPAN class=comment><FONT color=#238b23>/* Drop the last digit */</FONT></SPAN>
									}
									return ($1 ? args[$1] : "$") + literalNumbers;
							}
						<SPAN class=comment><FONT color=#238b23>/* Named backreference */</FONT></SPAN>
						} else if ($2) {
							<SPAN class=comment><FONT color=#238b23>/* What does "${name}" mean?
							- Backreference to named capture "name", if it exists
							- Else, it's the string "${name}" */</FONT></SPAN>
							var index = search._captureNames.indexOf($2);
							return index > -1 ? args[index + 1] : $0;
						} else {
							return $0;
						}
					});
				});
			}
		};
		
		RegExp.prototype.exec = function (str) {
			var result = native.exec.call(this, str);
			if (!(this._captureNames && result && result.length > 1)) return result;
			
			for (var i = 1; i < result.length; i++) {
				var name = this._captureNames[i - 1];
				if (name) result[name] = result[i];
			}
			
			return result;
		};
		
		String.prototype.match = function (regexp) {
			if (!regexp._captureNames || regexp.global) return native.match.call(this, regexp);
			return regexp.exec(this);
		};
	})();
}

<SPAN class=comment><FONT color=#238b23>/* Regex syntax parsing with support for escapings, character classes, and various other context and cross-browser issues */</FONT></SPAN>
XRegExp._re = {
	extended: /(?:[^[#\s\\]+|\\(?:[\S\s]|$)|\[\^?]?(?:[^\\\]]+|\\(?:[\S\s]|$))*]?)+|(\s*#[^\n\r]*\s*|\s+)([?*+]|{\d+(?:,\d*)?})?/g,
	singleline: /(?:[^[\\.]+|\\(?:[\S\s]|$)|\[\^?]?(?:[^\\\]]+|\\(?:[\S\s]|$))*]?)+|\./g,
	characterClass: /(?:[^\\[]+|\\(?:[\S\s]|$))+|\[\^?(]?)(?:[^\\\]]+|\\(?:[\S\s]|$))*]?/g,
	capturingGroup: /(?:[^[(\\]+|\\(?:[\S\s]|$)|\[\^?]?(?:[^\\\]]+|\\(?:[\S\s]|$))*]?|\((?=\?))+|\((?:<([$\w]+)>)?/g,
	namedBackreference: /(?:[^\\[]+|\\(?:[^k]|$)|\[\^?]?(?:[^\\\]]+|\\(?:[\S\s]|$))*]?|\\k(?!<[$\w]+>))+|\\k<([$\w]+)>(\d*)/g,
	replacementVariable: /(?:[^$]+|\$(?![1-9$&`']|{[$\w]+}))+|\$(?:([1-9]\d*|[$&`'])|{([$\w]+)})/g
};

XRegExp.overrideNative = function () {
	<SPAN class=comment><FONT color=#238b23>/* Override the global RegExp constructor/object with the XRegExp constructor. This precludes accessing
	properties of the last match via the global RegExp object. However, those properties are deprecated as
	of JavaScript 1.5, and the values are available on RegExp instances or via RegExp/String methods. It also
	affects the result of (/x/.constructor == RegExp) and (/x/ instanceof RegExp), so use with caution. */</FONT></SPAN>
	RegExp = XRegExp;
};

<SPAN class=comment><FONT color=#238b23>/* indexOf method from Mootools 1.11; MIT License */</FONT></SPAN>
Array.prototype.indexOf = Array.prototype.indexOf || function (item, from) {
	var len = this.length;
	for (var i = (from < 0) ? Math.max(0, len + from) : from || 0; i < len; i++) {
		if (this[i] === item) return i;
	}
	return -1;
};
로그인 후 복사

You can download it, or get the packed version (2.7 KB).

XRegExp has been tested in IE 5.5–7, Firefox 2.0.0.4, Opera 9.21, Safari 3.0.2 beta for Windows, and Swift 0.2.

Finally, note that the <font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">XRE</font> object from v0.1 has been removed. XRegExp now only creates one global variable: <font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">XRegExp</font>. To permanently override the native <font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">RegExp</font> constructor/object, you can now run <font style="BACKGROUND-COLOR: #f5f5ff" color="#000088" size="2">XRegExp.overrideNative();</font>

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

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

인기 기사

R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
3 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
3 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
3 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

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

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

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

JavaScript로 문자열 문자를 교체하십시오 JavaScript로 문자열 문자를 교체하십시오 Mar 11, 2025 am 12:07 AM

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

자신의 Ajax 웹 응용 프로그램을 구축하십시오 자신의 Ajax 웹 응용 프로그램을 구축하십시오 Mar 09, 2025 am 12:11 AM

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

10 JQuery Fun 및 Games 플러그인 10 JQuery Fun 및 Games 플러그인 Mar 08, 2025 am 12:42 AM

10 재미있는 jQuery 게임 플러그인 웹 사이트를보다 매력적으로 만들고 사용자 끈적함을 향상시킵니다! Flash는 여전히 캐주얼 웹 게임을 개발하기위한 최고의 소프트웨어이지만 JQuery는 놀라운 효과를 만들 수 있으며 Pure Action Flash 게임과 비교할 수는 없지만 경우에 따라 브라우저에서 예기치 않은 재미를 가질 수 있습니다. jQuery tic 발가락 게임 게임 프로그래밍의 "Hello World"에는 이제 jQuery 버전이 있습니다. 소스 코드 jQuery Crazy Word Composition 게임 이것은 반은 반은 게임이며, 단어의 맥락을 알지 못해 이상한 결과를 얻을 수 있습니다. 소스 코드 jQuery 광산 청소 게임

내 자신의 JavaScript 라이브러리를 어떻게 작성하고 게시합니까? 내 자신의 JavaScript 라이브러리를 어떻게 작성하고 게시합니까? Mar 18, 2025 pm 03:12 PM

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

jQuery 시차 자습서 - 애니메이션 헤더 배경 jQuery 시차 자습서 - 애니메이션 헤더 배경 Mar 08, 2025 am 12:39 AM

이 튜토리얼은 jQuery를 사용하여 매혹적인 시차 배경 효과를 만드는 방법을 보여줍니다. 우리는 멋진 시각적 깊이를 만드는 계층화 된 이미지가있는 헤더 배너를 만들 것입니다. 업데이트 된 플러그인은 jQuery 1.6.4 이상에서 작동합니다. 다운로드

브라우저에서 성능을 위해 JavaScript 코드를 최적화하려면 어떻게해야합니까? 브라우저에서 성능을 위해 JavaScript 코드를 최적화하려면 어떻게해야합니까? Mar 18, 2025 pm 03:14 PM

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

Matter.js : 소개를 시작합니다 Matter.js : 소개를 시작합니다 Mar 08, 2025 am 12:53 AM

Matter.js는 JavaScript로 작성된 2D 강성 신체 물리 엔진입니다. 이 라이브러리를 사용하면 브라우저에서 2D 물리학을 쉽게 시뮬레이션 할 수 있습니다. 그것은 단단한 몸체를 생성하고 질량, 면적 또는 밀도와 같은 물리적 특성을 할당하는 능력과 같은 많은 기능을 제공합니다. 중력 마찰과 같은 다양한 유형의 충돌 및 힘을 시뮬레이션 할 수도 있습니다. Matter.js는 모든 주류 브라우저를 지원합니다. 또한, 터치를 감지하고 반응이 좋기 때문에 모바일 장치에 적합합니다. 이러한 모든 기능을 사용하면 엔진 사용 방법을 배울 수있는 시간이 필요합니다. 이는 물리 기반 2D 게임 또는 시뮬레이션을 쉽게 만들 수 있습니다. 이 튜토리얼에서는 설치 및 사용을 포함한이 라이브러리의 기본 사항을 다루고

jQuery 및 Ajax를 사용한 자동 새로 고침 DIV 컨텐츠 jQuery 및 Ajax를 사용한 자동 새로 고침 DIV 컨텐츠 Mar 08, 2025 am 12:58 AM

이 기사에서는 jQuery 및 Ajax를 사용하여 5 초마다 DIV의 컨텐츠를 자동으로 새로 고치는 방법을 보여줍니다. 이 예제는 RSS 피드의 최신 블로그 게시물을 마지막 새로 고침 타임 스탬프와 함께 가져오고 표시합니다. 로딩 이미지는 선택 사항입니다

See all articles