text
stringlengths
1
2.83M
id
stringlengths
16
152
metadata
dict
__index_level_0__
int64
0
949
// Copyright (c) 2022 8th Wall, Inc. /* globals AFRAME */ AFRAME.registerComponent('target-video', { schema: { name: {type: 'string'}, video: {type: 'string'}, }, init() { const {object3D} = this.el const {name} = this.data object3D.visible = false const v = document.querySelector(this.data.video) const showImage = ({detail}) => { if (name !== detail.name) { return } v.play() object3D.position.copy(detail.position) object3D.quaternion.copy(detail.rotation) object3D.scale.set(detail.scale, detail.scale, detail.scale) object3D.visible = true } const hideImage = ({detail}) => { if (name !== detail.name) { return } v.pause() object3D.visible = false } this.el.sceneEl.addEventListener('xrimagefound', showImage) this.el.sceneEl.addEventListener('xrimageupdated', showImage) this.el.sceneEl.addEventListener('xrimagelost', hideImage) }, })
8thwall/web/examples/aframe/alpha-video/target-video.js/0
{ "file_path": "8thwall/web/examples/aframe/alpha-video/target-video.js", "repo_id": "8thwall", "token_count": 416 }
0
// Copyright (c) 2021 8th Wall, Inc. /* globals AFRAME */ // This component hides and shows certain elements as the camera moves AFRAME.registerComponent('portal', { schema: { width: {default: 4}, height: {default: 6}, depth: {default: 1}, }, init() { this.camera = document.getElementById('camera') this.contents = document.getElementById('portal-contents') this.walls = document.getElementById('hider-walls') this.portalWall = document.getElementById('portal-wall') this.isInPortalSpace = false this.wasOutside = true }, tick() { const {position} = this.camera.object3D const isOutside = position.z > this.data.depth / 2 const withinPortalBounds = position.y < this.data.height && Math.abs(position.x) < this.data.width / 2 if (this.wasOutside !== isOutside && withinPortalBounds) { this.isInPortalSpace = !isOutside } this.contents.object3D.visible = this.isInPortalSpace || isOutside this.walls.object3D.visible = !this.isInPortalSpace && isOutside this.portalWall.object3D.visible = this.isInPortalSpace && !isOutside this.wasOutside = isOutside }, }) AFRAME.registerComponent('bob', { schema: { distance: {default: 0.15}, duration: {default: 1000}, }, init() { const {el} = this const {data} = this data.initialPosition = this.el.object3D.position.clone() data.downPosition = data.initialPosition.clone().setY(data.initialPosition.y - data.distance) data.upPosition = data.initialPosition.clone().setY(data.initialPosition.y + data.distance) const vectorToString = v => `${v.x} ${v.y} ${v.z}` data.initialPosition = vectorToString(data.initialPosition) data.downPosition = vectorToString(data.downPosition) data.upPosition = vectorToString(data.upPosition) data.timeout = null const animatePosition = position => el.setAttribute('animation__bob', { property: 'position', to: position, dur: data.duration, easing: 'easeInOutQuad', loop: false, }) const bobDown = () => { if (data.shouldStop) { animatePosition(data.initialPosition) data.stopped = true return } animatePosition(data.downPosition) data.timeout = setTimeout(bobUp, data.duration) } const bobUp = () => { if (data.shouldStop) { animatePosition(data.initialPosition) data.stopped = true return } animatePosition(data.upPosition) data.timeout = setTimeout(bobDown, data.duration) } const bobStop = () => { data.shouldStop = true } const bobStart = () => { if (data.stopped) { data.shouldStop = false data.stopped = false bobUp() } } this.el.addEventListener('bobStart', bobStart) this.el.addEventListener('bobStop', bobStop) bobUp() }, })
8thwall/web/examples/aframe/portal/portal-components.js/0
{ "file_path": "8thwall/web/examples/aframe/portal/portal-components.js", "repo_id": "8thwall", "token_count": 1123 }
1
const reportWebVitals = (onPerfEntry) => { if (onPerfEntry && onPerfEntry instanceof Function) { import('web-vitals').then(({getCLS, getFID, getFCP, getLCP, getTTFB}) => { getCLS(onPerfEntry) getFID(onPerfEntry) getFCP(onPerfEntry) getLCP(onPerfEntry) getTTFB(onPerfEntry) }) } } export default reportWebVitals
8thwall/web/examples/aframe/reactapp/src/reportWebVitals.js/0
{ "file_path": "8thwall/web/examples/aframe/reactapp/src/reportWebVitals.js", "repo_id": "8thwall", "token_count": 164 }
2
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>8th Wall Web: babylon.js</title> <link rel="stylesheet" type="text/css" href="index.css"> <!-- Babylon.js --> <script src="//cdn.jsdelivr.net/npm/babylonjs@4.1.0/babylon.min.js"></script> <script src="//cdn.jsdelivr.net/npm/babylonjs-loaders@4.1.0/babylonjs.loaders.min.js"></script> <!-- Javascript tweening engine --> <script src="//cdnjs.cloudflare.com/ajax/libs/tween.js/18.6.4/tween.umd.js"></script> <!-- XR Extras - provides utilities like load screen, almost there, and error handling. See github.com/8thwall/web/tree/master/xrextras --> <script src="//cdn.8thwall.com/web/xrextras/xrextras.js"></script> <!-- 8thWall Web - Replace the app key here with your own app key --> <script async src="//apps.8thwall.com/xrweb?appKey=XXXXXXXX"></script> <!-- client code --> <script src="index.js"></script> </head> <body> <canvas id="renderCanvas"></canvas> </body> </html>
8thwall/web/examples/babylonjs/placeground/index.html/0
{ "file_path": "8thwall/web/examples/babylonjs/placeground/index.html", "repo_id": "8thwall", "token_count": 466 }
3
/* Ported to JavaScript by Lazar Laszlo 2011 lazarsoft@gmail.com, www.lazarsoft.info */ /* * * Copyright 2007 ZXing authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function DataBlock(numDataCodewords, codewords) { this.numDataCodewords = numDataCodewords; this.codewords = codewords; this.__defineGetter__("NumDataCodewords", function() { return this.numDataCodewords; }); this.__defineGetter__("Codewords", function() { return this.codewords; }); } DataBlock.getDataBlocks=function(rawCodewords, version, ecLevel) { if (rawCodewords.length != version.TotalCodewords) { throw "ArgumentException"; } // Figure out the number and size of data blocks used by this version and // error correction level var ecBlocks = version.getECBlocksForLevel(ecLevel); // First count the total number of data blocks var totalBlocks = 0; var ecBlockArray = ecBlocks.getECBlocks(); for (var i = 0; i < ecBlockArray.length; i++) { totalBlocks += ecBlockArray[i].Count; } // Now establish DataBlocks of the appropriate size and number of data codewords var result = new Array(totalBlocks); var numResultBlocks = 0; for (var j = 0; j < ecBlockArray.length; j++) { var ecBlock = ecBlockArray[j]; for (var i = 0; i < ecBlock.Count; i++) { var numDataCodewords = ecBlock.DataCodewords; var numBlockCodewords = ecBlocks.ECCodewordsPerBlock + numDataCodewords; result[numResultBlocks++] = new DataBlock(numDataCodewords, new Array(numBlockCodewords)); } } // All blocks have the same amount of data, except that the last n // (where n may be 0) have 1 more byte. Figure out where these start. var shorterBlocksTotalCodewords = result[0].codewords.length; var longerBlocksStartAt = result.length - 1; while (longerBlocksStartAt >= 0) { var numCodewords = result[longerBlocksStartAt].codewords.length; if (numCodewords == shorterBlocksTotalCodewords) { break; } longerBlocksStartAt--; } longerBlocksStartAt++; var shorterBlocksNumDataCodewords = shorterBlocksTotalCodewords - ecBlocks.ECCodewordsPerBlock; // The last elements of result may be 1 element longer; // first fill out as many elements as all of them have var rawCodewordsOffset = 0; for (var i = 0; i < shorterBlocksNumDataCodewords; i++) { for (var j = 0; j < numResultBlocks; j++) { result[j].codewords[i] = rawCodewords[rawCodewordsOffset++]; } } // Fill out the last data block in the longer ones for (var j = longerBlocksStartAt; j < numResultBlocks; j++) { result[j].codewords[shorterBlocksNumDataCodewords] = rawCodewords[rawCodewordsOffset++]; } // Now add in error correction blocks var max = result[0].codewords.length; for (var i = shorterBlocksNumDataCodewords; i < max; i++) { for (var j = 0; j < numResultBlocks; j++) { var iOffset = j < longerBlocksStartAt?i:i + 1; result[j].codewords[iOffset] = rawCodewords[rawCodewordsOffset++]; } } return result; }
8thwall/web/examples/camerapipeline/qrcode/jsqrcode/src/datablock.js/0
{ "file_path": "8thwall/web/examples/camerapipeline/qrcode/jsqrcode/src/datablock.js", "repo_id": "8thwall", "token_count": 1196 }
4
<!doctype html> <html> <head> <title>8thWall Web: Simple Shaders</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> <link rel="stylesheet" type="text/css" href="index.css"> <!-- XR Extras - provides utilities like load screen, almost there, and error handling. See github.com/8thwall/web/tree/master/xrextras --> <script src="//cdn.8thwall.com/web/xrextras/xrextras.js"></script> <!-- 8thWall Web - Replace the app key here with your own app key --> <script async src="//apps.8thwall.com/xrweb?appKey=XXXXXXXX"></script> <!-- Client code --> <script defer src="index.js"></script> </head> <body> <canvas id="camerafeed"></canvas> <div class="nextbutton" id="nextbutton">Next &gt;</div> </body> </html>
8thwall/web/examples/camerapipeline/simpleshaders/index.html/0
{ "file_path": "8thwall/web/examples/camerapipeline/simpleshaders/index.html", "repo_id": "8thwall", "token_count": 310 }
5
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>8th Wall Web: babylon.js</title> <link rel="stylesheet" type="text/css" href="index.css"> <!-- Babylon.js --> <script src="//cdn.jsdelivr.net/npm/babylonjs@5.4.0/babylon.min.js" crossorigin="anonymous"></script> <script src="//cdn.jsdelivr.net/npm/babylonjs-materials@5.4.0/babylonjs.materials.min.js" crossorigin="anonymous"></script> <!-- XR Extras - provides utilities like load screen, almost there, and error handling. See github.com/8thwall/web/tree/master/xrextras --> <script src="//cdn.8thwall.com/web/xrextras/xrextras.js"></script> <!-- Landing Pages - see https://www.8thwall.com/docs/web/#landing-pages --> <script src='//cdn.8thwall.com/web/landing-page/landing-page.js'></script> <!-- 8thWall Web - Replace the app key here with your own app key --> <script async src="//apps.8thwall.com/xrweb?appKey=XXXXX"></script> <!-- client code --> <script src="index.js"></script> </head> <body> <canvas id="renderCanvas"></canvas> </body> </html>
8thwall/web/gettingstarted/babylonjs/index.html/0
{ "file_path": "8thwall/web/gettingstarted/babylonjs/index.html", "repo_id": "8thwall", "token_count": 485 }
6
/* globals AFRAME, XRExtras, XR8 */ import {xrComponents} from './xr-components' import {xrPrimitives} from './xr-primitives' import {ensureXrAndExtras} from './ensure' let xrextrasAframe = null const onxrloaded = () => { XR8.addCameraPipelineModule(XRExtras.Loading.pipelineModule()) } // We want to start showing the loading screen eagerly (before AFRAME has loaded and parsed the // scene and set up everything). We also need to work around a bug in the AFRAME loading in iOS // Webviews for almost there. const eagerload = () => { // Manually traverse the dom for an aframe scene and check its attributes. const scene = document.getElementsByTagName('a-scene')[0] if (!scene) { return } const attrs = scene.attributes let foundAlmostThere = false let foundLoading = false let redirectUrl = null let runConfig = null // Eagerly inspect the dom, and trigger loading or almost there modules early if appropriate. const xrconfigPresent = Array.from(attrs).map(attr => attr.name).includes('xrconfig') Object.keys(attrs).forEach((a) => { const attr = attrs.item(a).name if (attr === 'xrextras-almost-there') { foundAlmostThere = true const redirectMatch = new RegExp('url:([^;]*)').exec(attrs.item(a).value) if (redirectMatch) { redirectUrl = redirectMatch[1] } } if (attr === 'xrextras-loading') { foundLoading = true } // We use xrconfig if it is present, else xrweb or xrface or xrlayers. if (attr === 'xrconfig' || (!xrconfigPresent && (attr === 'xrweb' || attr === 'xrface' || attr === 'xrlayers'))) { const allowedDevicesMatch = new RegExp('allowedDevices:([^;]*)').exec(attrs.item(a).value) if (allowedDevicesMatch) { runConfig = {allowedDevices: allowedDevicesMatch[1].trim()} } } }) if (foundAlmostThere) { if (redirectUrl) { window.XRExtras.AlmostThere.configure({url: redirectUrl}) } // eslint-disable-next-line no-unused-expressions window.XR8 ? window.XRExtras.AlmostThere.checkCompatibility(runConfig) : window.addEventListener( 'xrloaded', () => window.XRExtras.AlmostThere.checkCompatibility(runConfig) ) } if (foundLoading) { const waitForRealityTexture = !!(scene.attributes.xrweb || scene.attributes.xrface || scene.attributes.xrlayers) window.XRExtras.Loading.showLoading({onxrloaded, waitForRealityTexture}) } } function create() { let registered = false // NOTE: new versions of 8frame should be added in descending order, so that the latest version // is always in position 1. const allowed8FrameVersions = ['latest', '0.9.0', '0.8.2'] const LATEST_8FRAME = allowed8FrameVersions[1] // The 'latest' version of 8frame. // Check that the requested version of AFrame has a corresponding 8Frame implementation. const checkAllowed8FrameVersions = version => new Promise((resolve, reject) => (allowed8FrameVersions.includes(version) ? resolve(version === 'latest' ? LATEST_8FRAME : version) : reject(`'${version}' is an unsupported AFrame version. Alowed versions: (${allowed8FrameVersions})`))) // Load an external javascript resource in a promise that resolves when the javascript has loaded. const loadJsPromise = url => new Promise((resolve, reject) => document.head.appendChild(Object.assign( document.createElement('script'), {async: true, onload: resolve, onError: reject, src: url} ))) // If XR or XRExtras load before AFrame, we need to manually register their AFrame components. const ensureAFrameComponents = () => { if (window.XR8) { window.AFRAME.registerComponent('xrconfig', XR8.AFrame.xrconfigComponent()) window.AFRAME.registerComponent('xrweb', XR8.AFrame.xrwebComponent()) window.AFRAME.registerComponent('xrface', XR8.AFrame.xrfaceComponent()) window.AFRAME.registerComponent('xrlayers', XR8.AFrame.xrlayersComponent()) window.AFRAME.registerComponent('xrlayerscene', XR8.AFrame.xrlayersceneComponent()) window.AFRAME.registerPrimitive('sky-scene', XR8.AFrame.skyscenePrimitive()) } // eslint-disable-next-line @typescript-eslint/no-unused-expressions window.XRExtras && window.XRExtras.AFrame.registerXrExtrasComponents() } // Register a map of component-name -> component, e.g. // { // 'component-1': component1, // 'component-2': component2, // } const registerComponents = components => Object.keys(components).map(k => AFRAME.registerComponent(k, components[k])) const registerPrimitives = primitives => Object.keys(primitives).map(k => AFRAME.registerPrimitive(k, primitives[k])) // Load the 8th Wall preferred version of AFrame at runtime ensuring that xr components are added. const loadAFrameForXr = (args) => { const {version = 'latest', components = {}} = args || {} return checkAllowed8FrameVersions(version) .then(ver => loadJsPromise(`//cdn.8thwall.com/web/aframe/8frame-${ver}.min.js`)) .then(ensureAFrameComponents) .then(ensureXrAndExtras) .then(_ => registerComponents(components)) } // Register XRExtras AFrame components. const registerXrExtrasComponents = () => { // If AFrame is not ready, or we already registered components, skip. if (registered || !window.AFRAME) { return } // Only register the components once. registered = true // Show the loading screen as early as we can - add a System because it will get `init` called // before assets finish loading, versus a Component which gets `init` after load. AFRAME.registerSystem('eager-load-system', { init() { try { /* eslint-disable-next-line no-unused-expressions */ window.XRExtras ? eagerload() : window.addEventListener('xrextrasloaded', eagerload, {once: true}) } catch (err) { // eslint-disable-next-line no-console console.error(err) } }, }) registerComponents(xrComponents()) registerPrimitives(xrPrimitives()) } // Eagerly try to register the aframe components, if aframe has already loaded. registerXrExtrasComponents() return { // Load the 8th Wall version of AFrame at runtime ensuring that xr components are added. loadAFrameForXr, // Register the XRExtras components. This should only be called after AFrame has loaded. registerXrExtrasComponents, } } const AFrameFactory = () => { if (!xrextrasAframe) { xrextrasAframe = create() } return xrextrasAframe } export { AFrameFactory, }
8thwall/web/xrextras/src/aframe/aframe.js/0
{ "file_path": "8thwall/web/xrextras/src/aframe/aframe.js", "repo_id": "8thwall", "token_count": 2343 }
7
* { font-family: inherit; box-sizing: inherit; } .absolute-fill { position: absolute; top: 0; left: 0; bottom: 0; right: 0; } .hidden { display: none !important; } .error-text-outer-container { display: flex; align-items: center; justify-content: center; } .error-text-container { flex: 0 0 auto; text-align: center; width: 100%; } .error-text-header { font-family: 'Nunito', sans-serif; font-size: 16pt; color: white; letter-spacing: .37; line-height: 23pt; } .xrextras-old-style .error-text-header { color: #323232; } .error-text-hint { font-family: 'Nunito', sans-serif; font-size: 14pt; color: #A8A8BA; letter-spacing: .37; } .error-text-detail { font-family: 'Nunito', sans-serif; font-size: 14pt; color: white; } .xrextras-old-style .error-text-detail { color: #323232; } .error-margin-top-5 { margin-top: 5vh; } .error-margin-top-20 { margin-top: 20vh; } .desktop-home-link { font-family: 'Nunito-SemiBold', sans-serif; padding-top: 5px; padding-bottom: 5px; padding-left: 10px; padding-right: 10px; border-radius: 10px; color: white; background-color: #464766; -webkit-user-select: all; /* Chrome 49+ */ -moz-user-select: all; /* Firefox 43+ */ -ms-user-select: all; /* No support yet */ user-select: all; pointer-events: auto; } .xrextras-old-style .desktop-home-link { color: #323232; background-color:rgba(173, 80, 255, 0.2); } .desktop-home-link.mobile { position: fixed; width: 100vw; font-size: 1.1em; font-weight: 800; border-radius: 0px; bottom: 30%; left: 50%; transform: translateX(-50%); } .xrextras-old-style .foreground-image { filter: invert(1); }
8thwall/web/xrextras/src/common.css/0
{ "file_path": "8thwall/web/xrextras/src/common.css", "repo_id": "8thwall", "token_count": 723 }
8
<div id="recorder" class="recorder-container"> <svg viewBox="0 0 38 38" class="progress-container"> <circle class="progress-track" r="16" cx="19" cy="19"></circle> <circle id="progressBar" class="progress-bar" r="16" cx="19" cy="19"></circle> <circle class="loading-circle" r="16" cx="19" cy="19"></circle> </svg> <button id="recorder-button" class="style-reset"> Record </button> </div> <div id="flashElement" class="flash-element"></div>
8thwall/web/xrextras/src/mediarecorder/record-button.html/0
{ "file_path": "8thwall/web/xrextras/src/mediarecorder/record-button.html", "repo_id": "8thwall", "token_count": 171 }
9
const STATS_URL = 'https://cdn.8thwall.com/web/aframe/stats.16.min.js' let statsModule = null const loadJsPromise = url => new Promise((resolve, reject) => ( document.head.appendChild( Object.assign( document.createElement('script'), {async: true, onload: resolve, onError: reject, src: url} ) ) )) const StatsFactory = () => { if (statsModule == null) { statsModule = create() } return statsModule } function create() { const pipelineModule = () => { let stats_ = null return { name: 'stats', onBeforeRun: () => ( window.Stats ? Promise.resolve() : loadJsPromise(STATS_URL) ), onAttach: () => { stats_ = new Stats() stats_.showPanel(0) stats_.dom.style.zIndex = 5000 stats_.dom.style.position = 'absolute' stats_.dom.style.top = '0px' stats_.dom.style.left = '0px' document.body.appendChild(stats_.dom) }, onUpdate: () => { stats_.update() }, onDetach: () => { document.body.removeChild(stats_.dom) stats_ = null }, } } return { // Creates a camera pipeline module that, when installed, adds a framerate stats element to // the window dom. If the Stats package is not yet loaded, it will load it. pipelineModule, } } export { StatsFactory, }
8thwall/web/xrextras/src/statsmodule/stats.js/0
{ "file_path": "8thwall/web/xrextras/src/statsmodule/stats.js", "repo_id": "8thwall", "token_count": 557 }
10
## ไธ€ใ€้ขœ่‰ฒๆจกๅผ ้ขœ่‰ฒๆจกๅผๆœ‰ไธค็ง๏ผš - RGBA `rgba(0,0,0,0.5); //้ป‘่‰ฒ๏ผŒ้€ๆ˜Žๅบฆ0.5` - HSLA๏ผˆ้ขœ่‰ฒ(0~360)๏ผŒ้ฅฑๅ’Œๅบฆ(0%~100%)๏ผŒๆ˜Žๅบฆ(0%~100%)๏ผŒ้€ๆ˜Žๅบฆ(0~1)๏ผ‰ **็บขๆฉ™้ป„็ปฟ้’่“็ดซ็บข**๏ผš้ขœ่‰ฒไปŽ 0~360 ้กบๅบ๏ผŒๅ„ๅ 30ๅบฆใ€‚ๆฏ”ๅฆ‚็บข่‰ฒไธบ0๏ผŒ้ป„่‰ฒไธบ120๏ผŒ็ปฟ่‰ฒไธบ240ใ€‚ `HSLA(0, 100%, 50%, 1); // ็บข่‰ฒไธ้€ๆ˜Ž๏ผŒ้ฅฑๅ’Œๅบฆ100%๏ผŒไบฎๅบฆ50%` ๆ˜Žๅบฆ้ป˜่ฎคๆ˜ฏ50%,ไธ€่ˆฌๅปบ่ฎฎไฟ็•™50็š„ๅ€ผ๏ผŒๅฆ‚ๆžœๅŠ ๅˆฐ100ๅŽ๏ผŒๅ˜ๆˆ็™ฝ่‰ฒ๏ผŒ้™ๅˆฐ0ๅŽไธบ้ป‘่‰ฒใ€‚ > ๆณจๆ„๏ผš > > 1ใ€RGBAๅ’ŒHSLAไธญ็š„้€ๆ˜Žๅบฆ**ไธไผšๅฝฑๅ“ๅญๅ…ƒ็ด ็š„้€ๆ˜Žๅบฆ๏ผŒไธๅ…ท็ปงๆ‰ฟๆ€ง๏ผ›** > > 2ใ€**opacity ไผšๅฝฑๅ“ๅญๅ…ƒ็ด ็š„้€ๆ˜Žๅบฆ๏ผŒๅญๅ…ƒ็ด ไผš็ปงๆ‰ฟ็ˆถๅ…ƒ็ด ็š„้€ๆ˜Žๅบฆใ€‚** > > 3ใ€**transparent ไธๅฏ่ฐƒ่Š‚้€ๆ˜Žๅบฆ๏ผŒๅง‹็ปˆๅฎŒๅ…จ้€ๆ˜Žใ€‚**๏ผˆ`color: transparent;`๏ผ‰ ## ไบŒใ€ๆ–‡ๅญ—้˜ดๅฝฑ ่ฏญๆณ•๏ผš ```css /*้˜ดๅฝฑๅฏไปฅๅ ๅŠ ๏ผŒไฝฟ็”จ้€—ๅท้š”ๅผ€*/ text-shadow: offsetX offsetY blur color, offsetX1 offsetY1 blur1 color1, ... ``` > `offsetX`๏ผšXๆ–นๅ‘ๅ็งปๅบฆ > > `offsetY`๏ผšYๆ–นๅ‘ๅ็งปๅบฆ > > `blur`๏ผš้˜ดๅฝฑ็š„ๆจก็ณŠๅบฆ > > `color`๏ผš้˜ดๅฝฑ้ขœ่‰ฒ ็คบไพ‹๏ผš ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> * { padding: 0; margin: 0; } .demo { width: 600px; padding: 30px; background-color: #666; margin: 20px auto; text-align: center; font: bold 80px/100% "ๅพฎ่ฝฏ้›…้ป‘"; color: #fff; } /*ๆทปๅŠ ้˜ดๅฝฑ text-shadow:offsetX offsetY blur color*/ .demo1 { text-shadow: -5px -5px 5px orange; } .demo2 { color: #000; text-shadow: 0 1px 0 #fff; } /*็ซ‹ไฝ“ๆตฎ้›•ๆ•ˆๆžœ*/ .demo3 { text-shadow: -1px -1px 0 red, -2px -2px 0 orange, -3px -3px 0 yellow, -4px -4px 0 green, -5px -5px 0 cyan, -6px -6px 0 blue, -7px -7px 0 purple; } .demo4 { text-shadow: 0 0 30px pink; } </style> </head> <body> <div class="demo demo1">ๆˆ‘ๆ˜ฏๆฑŸๅฐ็™ฝ</div> <div class="demo demo2">ๆˆ‘ๆ˜ฏๆฑŸๅฐ็™ฝ</div> <div class="demo demo3">ๆˆ‘ๆ˜ฏๆฑŸๅฐ็™ฝ</div> <div class="demo demo4">ๆˆ‘ๆ˜ฏๆฑŸๅฐ็™ฝ</div> </body> </html> ``` ![1](./images/1.png) ## ไธ‰ใ€็›’ๆจกๅž‹ 1ใ€ๅœจ้ป˜่ฎคๆƒ…ๅ†ตไธ‹๏ผŒCSS ่ฎพ็ฝฎ็š„็›’ๅญๅฎฝๅบฆไป…ไป…ๆ˜ฏๅ†…ๅฎนๅŒบ็š„ๅฎฝๅบฆ๏ผŒ่€Œ้ž็›’ๅญ็š„ๅฎฝๅบฆใ€‚ๅŒๆ ท๏ผŒ้ซ˜ๅบฆ็ฑปไผผใ€‚็œŸๆญฃ็›’ๅญ็š„ๅฎฝๅบฆ๏ผˆๅœจ้กต้ขๅ‘ˆ็Žฐๅ‡บๆฅ็š„ๅฎฝๅบฆ๏ผ‰ๅ’Œ้ซ˜ๅบฆ๏ผŒ้œ€่ฆๅŠ ไธŠไธ€ไบ›ๅ…ถๅฎƒ็š„ๅฑžๆ€งใ€‚ไพ‹ๅฆ‚๏ผš - padding + border + width = ็›’ๅญ็š„ๅฎฝๅบฆ - padding + border + height = ็›’ๅญ็š„้ซ˜ๅบฆ ๅพˆๆ˜Žๆ˜พ๏ผŒ่ฟ™ไธ็›ด่ง‚๏ผŒๅพˆๅฎนๆ˜“ๅ‡บ้”™๏ผŒ้€ ๆˆ็ฝ‘้กตไธญๅ…ถๅฎƒๅ…ƒ็ด ็š„้”™ไฝใ€‚ 2ใ€CSS3ไธญๅฏไปฅ้€š่ฟ‡`box-sizing` ๆฅๆŒ‡ๅฎš็›’ๆจกๅž‹๏ผŒๅณๅฏๆŒ‡ๅฎšไธบ`content-boxใ€border-box`๏ผŒ่ฟ™ๆ ทๆˆ‘ไปฌ่ฎก็ฎ—็›’ๅญๅคงๅฐ็š„ๆ–นๅผๅฐฑๅ‘็”Ÿไบ†ๆ”นๅ˜ใ€‚ - `content-box`๏ผšๅฏน่ฑก็š„ๅฎž้™…ๅฎฝๅบฆ็ญ‰ไบŽ่ฎพ็ฝฎ็š„ width ๅ€ผๅ’Œ borderใ€padding ไน‹ๅ’Œใ€‚**๏ผˆ็›’ๅญๅฎž้™…็š„ๅฎฝๅบฆ = ่ฎพ็ฝฎ็š„ width + padding + border๏ผ‰** - `border-box`๏ผš ๅฏน่ฑก็š„ๅฎž้™…ๅฎฝๅบฆๅฐฑ็ญ‰ไบŽ่ฎพ็ฝฎ็š„widthๅ€ผ๏ผŒๅณไฝฟๅฎšไน‰ๆœ‰ border ๅ’Œ padding ไนŸไธไผšๆ”นๅ˜ๅฏน่ฑก็š„ๅฎž้™…ๅฎฝๅบฆใ€‚**๏ผˆ็›’ๅญๅฎž้™…็š„ๅฎฝๅบฆ = ่ฎพ็ฝฎ็š„ width๏ผ‰**๏ผŒ็›ธๅบ”็š„็›’ๅญ็š„ๅ†…ๅฎน็š„ๅฎฝๅบฆๆˆ–้ซ˜ๅบฆๅŒบ้—ดไผšๅ˜ๅฐใ€‚ 3ใ€ๆต่งˆๅ™จ็š„ๅ…ผๅฎนๆ€ง IE8 ๅŠไปฅไธŠ็‰ˆๆœฌๆ”ฏๆŒ่ฏฅๅฑžๆ€ง๏ผŒFirefox ้œ€่ฆๅŠ ไธŠๆต่งˆๅ™จๅŽ‚ๅ•†ๅ‰็ผ€ `-moz-`๏ผŒๅฏนไบŽไฝŽ็‰ˆๆœฌ็š„ IOS ๅ’Œ Android ๆต่งˆๅ™จไนŸ้œ€่ฆๅŠ ไธŠ `-webkit-` ๆฌงๆœ‹ๆต่งˆๅ™จ๏ผšๅ‰็ผ€ -o- IEๆต่งˆๅ™จ๏ผšๅ‰็ผ€ -ms- ## ๅ››ใ€่พนๆก†ๅœ†่ง’ ไฝฟ็”จ `border-radius` ๅฑžๆ€งๆฅ่ฎพ็ฝฎๅœ†่ง’ใ€‚ ```css /*ๆทปๅŠ ่พนๆก†ๅœ†่ง’*/ /*1.่ฎพ็ฝฎไธ€ไธชๅ€ผ๏ผšๅ››ไธช่ง’็š„ๅœ†่ง’ๅ€ผ้ƒฝไธ€ๆ ท*/ border-radius: 10px; border-radius: 50%; /*2.่ฎพ็ฝฎไธคไธชๅ€ผ:็ฌฌไธ€ไธชๅ€ผๆŽงๅˆถๅทฆไธŠ/ๅณไธ‹๏ผŒ็ฌฌไบŒไธชๅ€ผๆŽงๅˆถๅณไธŠ/ๅทฆไธ‹*/ border-radius: 10px 30px; /*3.่ฎพ็ฝฎไธ‰ไธชๅ€ผ๏ผš็ฌฌไธ€ไธชๅ€ผๆŽงๅˆถๅทฆไธŠ๏ผŒ็ฌฌไบŒๅ€ผๆŽงๅˆถๅณไธŠ/ๅทฆไธ‹๏ผŒ็ฌฌไธ‰ไธชๅ€ผๆŽงๅˆถๅณไธ‹*/ border-radius: 10px 40px 60px; /*4.่ฎพ็ฝฎๅ››ไธชๅ€ผ๏ผšๅทฆไธŠ ๅณไธŠ ๅณไธ‹ ๅทฆไธ‹*/ border-radius: 10px 30px 60px 100px; /*5.ๆทปๅŠ /ๆ˜ฏ็”จๆฅ่ฎพ็ฝฎๅฝ“ๅ‰ๆฐดๅนณๅ’Œๅž‚็›ดๆ–นๅ‘็š„ๅŠๅพ„ๅ€ผ๏ผšๆฐดๅนณxๆ–นๅ‘/ๅž‚็›ดyๆ–นๅ‘*/ border-radius: 100px/50px; /*6.ๆทปๅŠ ๆŸไธช่ง’็‚น็š„ๅœ†่ง’*/ border-radius: 0px 50px 0px 0px; /*ๆˆ–่€…๏ผšborder-ไธŠไธ‹-ๅทฆๅณ-radius:*/ border-top-right-radius: 100px; border-top-left-radius: 100px;*/ border-bottom-left-radius: 100px; border-bottom-right-radius: 100px; /*7.่ฎพ็ฝฎๆŸไธช่ง’็‚น็š„ไธคไธชๆ–นๅ‘ไธŠ็š„ไธๅŒๅœ†่ง’*/ border-top-right-radius: 100px 50px; /*่ฎพ็ฝฎไธŠๅ็งป100px๏ผŒๅณๅ็งป50pxๆ ทๅผ็š„ๅœ†่ง’*/ border-bottom-left-radius: 80px 40px; /*่ฎพ็ฝฎไธ‹ๅ็งป80px๏ผŒๅทฆๅ็งป40pxๆ ทๅผ็š„ๅœ†่ง’*/ border-bottom-right-radius: 60px 30px;/*่ฎพ็ฝฎไธ‹ๅ็งป60px๏ผŒๅณๅ็งป30pxๆ ทๅผ็š„ๅœ†่ง’*/ border-top-left-radius: 40px 20px; /*่ฎพ็ฝฎไธŠๅ็งป40px๏ผŒๅทฆๅ็งป20pxๆ ทๅผ็š„ๅœ†่ง’*/ /*8.ๅฆ‚ๆžœๆƒณ่ฎพ็ฝฎๅ››ไธช่ง’็‚น็š„ไธๅŒๆ–นๅ‘ไธŠ็š„ไธๅŒๅœ†่ง’ๅ€ผ*/ /*ๅˆ†ๅˆซๆ˜ฏๆฐดๅนณๆ–นๅ‘็š„ๅ็งป๏ผšๅทฆไธŠ๏ผŒๅณไธŠ๏ผŒๅณไธ‹๏ผŒๅทฆไธ‹ ๏ผŒๅž‚็›ดๆ–นๅ‘็š„ๅ็งป๏ผšๅทฆไธŠ๏ผŒๅณไธŠ๏ผŒๅณไธ‹๏ผŒๅทฆไธ‹*/ border-radius: 100px 0px 0px 0px/20px 0px 0px 0px; ``` ## ไบ”ใ€่พนๆก†้˜ดๅฝฑ ่ฏญๆณ•๏ผš ```css box-shadow:h v blur spread color inset ``` > `h`๏ผšๆฐดๅนณๆ–นๅ‘็š„ๅ็งปๅ€ผ๏ผˆๅฟ…ๅกซ๏ผ‰ > `v`๏ผšๅž‚็›ดๆ–นๅ‘็š„ๅ็งปๅ€ผ๏ผˆๅฟ…ๅกซ๏ผ‰ > `blur`๏ผšๆจก็ณŠๅบฆ--ๅฏ้€‰๏ผŒ้ป˜่ฎค0 ๏ผˆๅฟ…ๅกซ๏ผ‰ > `spread`๏ผš้˜ดๅฝฑ็š„ๅฐบๅฏธ๏ผŒๆ‰ฉๅฑ•ๅ’Œๆ”ถ็ผฉ้˜ดๅฝฑ็š„ๅคงๅฐ--ๅฏ้€‰ ้ป˜่ฎค0 > `color`๏ผš้ขœ่‰ฒ--ๅฏ้€‰๏ผŒ้ป˜่ฎค้ป‘่‰ฒ > `inset`๏ผšๅ†…้˜ดๅฝฑ--ๅฏ้€‰,้ป˜่ฎคๆ˜ฏๅค–้˜ดๅฝฑ ๅฝ“็„ถ๏ผŒbox-shadow ๅ’Œ text-shadow ไธ€ๆ ท๏ผŒไนŸๆ˜ฏๅฏไปฅๆทปๅŠ ๅคšไธช็š„๏ผŒไน‹้—ด็”จ้€—ๅท้š”ๅผ€ใ€‚ ```css box-shadow: 10px 10px 5px pink (inset), -10px -10px 5px pink; /*spread็ญ‰ไธ้œ€่ฆ๏ผŒ็œ็•ฅไธๅ†™*/ ``` ![](./images/0.png)
Daotin/Web/02-CSS/02-CSS3/02-้ขœ่‰ฒๆจกๅผ๏ผŒๆ–‡ๅญ—้˜ดๅฝฑ๏ผŒ็›’ๆจกๅž‹๏ผŒ่พนๆก†ๅœ†่ง’๏ผŒ่พนๆก†้˜ดๅฝฑ.md/0
{ "file_path": "Daotin/Web/02-CSS/02-CSS3/02-้ขœ่‰ฒๆจกๅผ๏ผŒๆ–‡ๅญ—้˜ดๅฝฑ๏ผŒ็›’ๆจกๅž‹๏ผŒ่พนๆก†ๅœ†่ง’๏ผŒ่พนๆก†้˜ดๅฝฑ.md", "repo_id": "Daotin", "token_count": 3831 }
11
## 1ใ€ๅ‡ฝๆ•ฐ็š„ๅฎšไน‰ ```javascript // ็ฌฌไธ€็ง๏ผšๅฃฐๆ˜Žๅผๅ‡ฝๆ•ฐ------------------------------- function fn1(){ console.log("ๆˆ‘ๆ˜ฏ็ฌฌไธ€็งๅฎšไน‰ๆ–นๆณ•๏ผ"); } // ็ฌฌไบŒ็ง๏ผš่ต‹ๅ€ผๅผๅ‡ฝๆ•ฐ------------------------------------ var fn2 = function (){ console.log("ๆˆ‘ๆ˜ฏ็ฌฌไบŒ็งๅฎšไน‰ๆ–นๆณ•๏ผ"); }; // ๆณจๆ„ๅˆ†ๅท // ไฝฟ็”จๆ–นๅผ1๏ผš fn2(); // ไฝฟ็”จๆ–นๅผ2๏ผšๅ‡ฝๆ•ฐ็š„่‡ช่ฐƒ็”จ (function (a,b){ ใ€€ใ€€console.log("ๆˆ‘ๆ˜ฏ็ฌฌไบŒ็งๅฎšไน‰ๆ–นๆณ•๏ผ" + a+b); // ๆˆ‘ๆ˜ฏ็ฌฌไบŒ็งๅฎšไน‰ๆ–นๆณ•๏ผ3 })(1,2); // ๅŽ้ข็š„้ขๅฐๆ‹ฌๅท็”จๆฅไผ ๅ…ฅๅ‚ๆ•ฐ //็ฌฌไธ‰็ง----------------------------------------------------- var fn3 = new Function("a", "b", "console.log('ๆˆ‘ๆ˜ฏ็ฌฌไธ‰็งๅฎšไน‰ๆ–นๆณ•๏ผ' + a + b)"); ``` > **็ฌฌไธ€็ง๏ผš**๏ผˆๅ‡ฝๆ•ฐ็š„ๅฃฐๆ˜Ž๏ผ‰็ฌฌไธ€็งๅฎšไน‰ๆ–นๆณ•ๆœ€ๅผบๅคง๏ผŒๅฎšไน‰ๅฎŒๆฏ•ๅŽ๏ผŒๅœจๅ“ช้‡Œไฝฟ็”จ้ƒฝๅฏไปฅ๏ผŒๆ— ไฝ็ฝฎ้™ๅˆถใ€‚ > > **็ฌฌไบŒ็ง๏ผš**(ๅ‡ฝๆ•ฐ่กจ่พพๅผ๏ผšๅŒฟๅๅ‡ฝๆ•ฐ) ๅŽไธค็งๅฎšไน‰ๆ–นๆณ•ๆ˜ฏๆœ‰ๅฑ€้™ๆ€ง็š„ใ€‚๏ผˆไฝฟ็”จๅ‡ฝๆ•ฐๅฟ…้กปๅœจๅฎšไน‰ๅ‡ฝๆ•ฐไน‹ๅŽ๏ผ‰็ฌฌไบŒ็งๅ‡ฝๆ•ฐ็š„้”€ๆฏไฝฟ็”จ `fn2 = null;` ็ฌฌไธ€็งๆ–นๅผไธๅฏ้”€ๆฏใ€‚ > > **็ฌฌไธ‰็ง๏ผš**new Function ็š„ๆ–นๅผๅฎšไน‰็š„ๅ‡ฝๆ•ฐ้žๅธธๅผบๅคง๏ผŒๅ› ไธบๆ‰ง่กŒ็š„ๅ‡ฝๆ•ฐไปฃ็ ๆ˜ฏไปฅๅญ—็ฌฆไธฒ็š„ๅฝขๅผไผ ๅ…ฅ็š„๏ผŒ้‚ฃไนˆๅฐฑๅฏไปฅไปŽๅœฐๅ€ๆ ไผ ๅ…ฅ๏ผŒ่ฟ˜ๅฏไปฅไปŽๅŽๅฐไผ ๅ…ฅ๏ผŒ่ฟ™ๅฐฑๅพˆ็‰›้€ผไบ†๏ผŒๅ‡ฝๆ•ฐ็š„ไปฃ็ ็ซŸ็„ถไธๅ†™ๅœจๅ‡ฝๆ•ฐไฝ“้‡Œ้ขใ€‚ใ€‚ใ€‚ ## 2ใ€ๅ‡ฝๆ•ฐ็š„่ฐƒ็”จ ```javascript // 1.ๅ‡ฝๆ•ฐๅ(); foo(); //2.ๅ‡ฝๆ•ฐ่‡ช่ฐƒ็”จใ€‚ // ๅ‡ฝๆ•ฐ็š„่‡ช่ฐƒ็”จ๏ผŒไป…ๆ‰ง่กŒไธ€ๆฌกใ€‚ // ๅ‡ฝๆ•ฐ็š„ๅ‚ๆ•ฐๅธฆๅ…ฅ้€š่ฟ‡ๅŽ้ข็š„ๅฐๆ‹ฌๅทๅธฆๅ…ฅๆ•ฐๆฎ. // ่ฟ™ๆ ทๅ†™๏ผŒ้‡Œ้ข็š„ๅ†…ๅฎนๅฐฑๆ˜ฏ็งๆœ‰็š„ๅ˜้‡ๆˆ–่€…ๅ‡ฝๆ•ฐ๏ผŒๅฐฑๅฝขๆˆไบ†ๅฐ้—ญ็ฉบ้—ด (function(){})(); // 3.ไฝฟ็”จcall๏ผŒapply foo.call(null,ๅ‚ๆ•ฐ1๏ผŒๅ‚ๆ•ฐ2, ...); foo.apply(null,[ๅ‚ๆ•ฐ1๏ผŒๅ‚ๆ•ฐ2, ...]); ``` ## 3ใ€ๅ‡ฝๆ•ฐๅ - ่ฆ้ตๅพช้ฉผๅณฐๅ‘ฝๅๆณ•ใ€‚ - ไธ่ƒฝๅŒๅ๏ผˆๅ‡ฝๆ•ฐ้‡่ฝฝ๏ผ‰๏ผŒๅฆๅˆ™ๅŽ้ข็š„ๅ‡ฝๆ•ฐไผš่ฆ†็›–ๅ‰้ข็š„ๅ‡ฝๆ•ฐใ€‚ ```js //ๆ‰“ๅฐๅ‡ฝๆ•ฐๅ๏ผŒๅฐฑ็ญ‰ไบŽๆ‰“ๅฐๆ•ดไธชๅ‡ฝๆ•ฐใ€‚ console.log(fn); //ๆ‰“ๅฐๆ‰ง่กŒๅ‡ฝๆ•ฐ๏ผŒๅฐฑ็ญ‰ไบŽๆ‰“ๅฐๅ‡ฝๆ•ฐ็š„่ฟ”ๅ›žๅ€ผใ€‚ console.log(fn()); ``` ## 4ใ€ๅฝขๅ‚ๅ’Œๅฎžๅ‚ - ๅฝขๅ‚ไธ้œ€่ฆๅ†™ var. - ๅฝขๅ‚็š„ไธชๆ•ฐๅ’Œๅฎžๅ‚็š„ไธชๆ•ฐๅฏไปฅไธไธ€่‡ด ใ€‚ ## 5ใ€่ฟ”ๅ›žๅ€ผ 1. ๅฆ‚ๆžœๅ‡ฝๆ•ฐๆฒกๆœ‰ๆ˜พ็คบ็š„ไฝฟ็”จ return ่ฏญๅฅ ๏ผŒ้‚ฃไนˆๅ‡ฝๆ•ฐๆœ‰้ป˜่ฎค็š„่ฟ”ๅ›žๅ€ผ๏ผšundefined 2. ๅฆ‚ๆžœๅ‡ฝๆ•ฐไฝฟ็”จ return ่ฏญๅฅ๏ผŒไฝ†ๆ˜ฏ return ๅŽ้ขๆฒกๆœ‰ไปปไฝ•ๅ€ผ๏ผŒ้‚ฃไนˆๅ‡ฝๆ•ฐ็š„่ฟ”ๅ›žๅ€ผไนŸๆ˜ฏ๏ผšundefined. **return ๅฏไปฅ่ฟ”ๅ›ž็š„็ฑปๅž‹ๅŒ…ๅซไธ‹ๅˆ—ๅ‡ ็ง๏ผš** ### 1ใ€ๅทฅๅŽ‚ๆจกๅผ ่ฆๆฑ‚๏ผš - ๅ‡ฝๆ•ฐๅ†…้ƒจๅˆ›ๅปบไธ€ไธชๅฏน่ฑก๏ผŒ็”ฑไธ€ไธชๅฑ€้ƒจๅ˜้‡ๆŽฅๆ”ถ๏ผŒ็„ถๅŽ่ฟ”ๅ›ž่ฟ™ไธชๅฏน่ฑกใ€‚ - ๅฏไปฅ้€š่ฟ‡ๅ‡ฝๆ•ฐๅ‚ๆ•ฐๆ”นๅ˜ๅฏน่ฑก็š„ๅ†…ๅฎน ```js function fn2(w,color) { var div=document.createElement("div"); Object.assign(div.style,{ width:(w || 50)+"px", height:(w || 50)+"px", backgroundColor:color || "red", position:"absolute" }); return div; } fn2(100, "blue"); ``` ### 2ใ€ๅ•ไพ‹ๆจกๅผ ```js var obj={ divs:null, createDiv:function (w,color) { if(!this.divs){ this.divs=document.createElement("div"); Object.assign(this.divs.style,{ width:(w || 50)+"px", height:(w || 50)+"px", backgroundColor:color || "red" }); } return this.divs; } }; obj.createDiv(100, "blue"); obj.createDiv(100, "blue"); ``` ### 3ใ€้€š่ฟ‡ๅ‚ๆ•ฐไผ ๅ…ฅๅฏน่ฑก ```js function fn3(obj) { obj.a=10; return obj; } var objs={ a:1, b:2 }; var obj2=fn3(objs); console.log(obj2===objs);//true ไผ ๅ…ฅ็š„ๆ˜ฏๅฏน่ฑก็š„ๅผ•็”จ ``` ### 4ใ€้€š่ฟ‡ๅ‚ๆ•ฐไผ ๅ…ฅๅ‡ฝๆ•ฐ ```js // ๅ‚ๆ•ฐๅฐฑๆ˜ฏๅ‡ฝๆ•ฐ๏ผŒ่ฟ”ๅ›ž็š„ๆ˜ฏๅ‚ๆ•ฐ็š„ๆ‰ง่กŒ็ป“ๆžœ function fn4(fn) { return fn(); } function fn5() { return 5; } function fn6() { return 6; } console.log(fn4(fn5)); // 5 console.log(fn4(fn6)); // 6 ``` ### 5ใ€่ฟ”ๅ›žไธ€ไธช็งๅฏ†ๅฏน่ฑก ```js // ่ฟ”ๅ›žไธ€ไธช็งๅฏ†็š„ๅฏน่ฑก๏ผŒๆœ‰็งๆœ‰ๅ˜้‡ function fn7() { return (function () { var c=10; return { a:1, b:2, d:c } })(); } console.log(fn7()); // ็งๆœ‰ๅ˜้‡ c ``` ### 6ใ€่ฟ”ๅ›žๅคšไธชๅ…ƒ็ด ็š„ๆ•ฐ็ป„๏ผˆES5ไธญ็š„่งฃๆž„่ต‹ๅ€ผ๏ผ‰ ```js function fn8() { var div=document.createElement("div"); var input=document.createElement("input"); return [div,input]; } let [div,input]=fn8(); document.body.appendChild(div); document.body.appendChild(input); ``` ### 7ใ€่ฟ”ๅ›žๅคšไธชๅ…ƒ็ด ็š„ๅฏน่ฑก๏ผˆES6ไธญ่งฃๆž„่ต‹ๅ€ผ๏ผ‰ ```js function fn9() { return {a:1,b:2} } let {a,b}=fn9(); console.log(a,b); // 1,2 ``` ### 8ใ€ไผ ๅ…ฅๅ‚ๆ•ฐไธบๅ‡ฝๆ•ฐ๏ผŒ่ฟ”ๅ›žๅฏน่ฑก ```js function fn10(fn,obj) { return fn.bind(obj || {}); } function fn11(a,b) { this.a=a; this.b=b; return this; } function fn12(c,d) { this.c=c; this.d=d; return this; } var obj5={f:50}; console.log(fn10(fn11)(10,20)); // {a:10,b:20} console.log(fn10(fn12,obj5)(30,50)); //{c:30,d:50,f:50} ``` ### 9ใ€่ฟ”ๅ›žๅ‡ฝๆ•ฐ ```js function fn13() { return function (a,b) { console.log(a,b); } } fn13()(8,9); ``` ## 6ใ€ๅ˜้‡ๅ’Œไฝœ็”จๅŸŸ **ๅ…จๅฑ€ๅ˜้‡**๏ผš 1ใ€ๅœจ script ไฝฟ็”จ var ๅฎšไน‰็š„ๅ˜้‡๏ผˆๆ‰€ๆœ‰็š„ script ๅ…ฑไบซๅ…ถๅ…จๅฑ€ๆ€ง๏ผŒjs ้‡Œ้ขๆฒกๆœ‰ๅ—็บงไฝœ็”จๅŸŸๆฆ‚ๅฟต๏ผŒๅชๆœ‰ๅ…จๅฑ€ไฝœ็”จๅŸŸๅ’Œๅฑ€้ƒจไฝœ็”จๅŸŸ๏ผ‰ใ€‚ 2ใ€ๅœจ script ๆฒกๆœ‰ var ็š„ๅ˜้‡๏ผˆๅณไฝฟๅœจๅ‡ฝๆ•ฐๅ†…้ƒจ๏ผ‰ใ€‚ 3ใ€ไฝฟ็”จwindowๅ…จๅฑ€ๅฏน่ฑกๆฅๅฃฐๆ˜Ž๏ผŒๅ…จๅฑ€ๅฏน่ฑก็š„ๅฑžๆ€งๅฏนๅบ”ไนŸๆ˜ฏๅ…จๅฑ€ๅ˜้‡ใ€‚`window.test = 50; ` ```javascript function fn(){ ใ€€ใ€€var a = b = c = 1;ใ€€ใ€€ // bๅ’Œcๅฐฑๆ˜ฏ้šๅผๅ…จๅฑ€ๅ˜้‡๏ผˆ็ญ‰ๅท๏ผ‰ ใ€€ใ€€var a = 1; b = 2; c = 3; // bๅ’Œcๅฐฑๆ˜ฏ้šๅผๅ…จๅฑ€ๅ˜้‡๏ผˆๅˆ†ๅท๏ผ‰ ใ€€ใ€€var a = 1 , b = 2 , c = 3; // bๅ’Œcๅฐฑไธๆ˜ฏ้šๅผๅ…จๅฑ€ๅ˜้‡๏ผˆ้€—ๅท๏ผ‰ } ``` ๏ผˆๅ…จๅฑ€ๅ˜้‡ๆ˜ฏไธ่ƒฝ่ขซๅˆ ้™ค็š„๏ผŒ้šๅผๅ…จๅฑ€ๅ˜้‡ๆ˜ฏๅฏไปฅ่ขซๅˆ ้™ค็š„๏ผ‰ ```javascript var num1 = 10; num2 = 20; delete num1; delete num2; console.log(typeof num1); // number console.log(typeof num2); // undefined ``` **ๅฑ€้ƒจๅ˜้‡**๏ผš 1ใ€ๅ‡ฝๆ•ฐๅ†…้ƒจ็”จ var ๅฎšไน‰็š„ๅ˜้‡ใ€‚ 2ใ€ๅ‡ฝๆ•ฐ็š„ๅฝขๅ‚ใ€‚ ### 6.1ใ€ๅ˜้‡ๅฃฐๆ˜Žๆๅ‡๏ผˆ้ข„่งฃๆž๏ผ‰ **ไฝœ็”จ๏ผš**ๆŸฅ็œ‹่ฏญๆณ•้”™่ฏฏใ€‚js็š„่งฃๆžๅ™จๅœจ้กต้ขๅŠ ่ฝฝ็š„ๆ—ถๅ€™๏ผŒ้ฆ–ๅ…ˆๆฃ€ๆŸฅ้กต้ขไธŠ็š„่ฏญๆณ•้”™่ฏฏใ€‚ๆŠŠๅ˜้‡ๅฃฐๆ˜Žๆๅ‡่ตทๆฅใ€‚๏ผˆๅ˜้‡ๅฃฐๆ˜Žๆๅ‡ๅ’Œๅ‡ฝๆ•ฐๆ•ดไฝ“ๆๅ‡๏ผ‰ ### 6.2ใ€ๅ˜้‡็š„ๆๅ‡ **ๅชๆๅ‡ๅ˜้‡ๅ๏ผŒไธๆๅ‡ๅ˜้‡ๅ€ผใ€‚** ```javascript consolas.log(aaa);// ๆ‰“ๅฐ็š„็ป“ๆžœๆ˜ฏ undefined ๏ผŒๅ› ไธบๅชๆๅ‡ๅ˜้‡ๅ๏ผŒไธๆๅ‡ๅ˜้‡ๅ€ผใ€‚ var aaa = 111; ``` ๅœจๅ‡ฝๆ•ฐ่Œƒๅ›ดๅ†…๏ผŒ็…งๆ ท้€‚็”จใ€‚ ### 6.3ใ€ๅ‡ฝๆ•ฐ็š„ๆๅ‡ function ็›ดๆŽฅๅฎšไน‰็š„ๆ–นๆณ•๏ผšๆ•ดไฝ“ๆๅ‡๏ผˆไธŠ้ข่ฏด็š„็ฌฌไธ€็งๅ‡ฝๆ•ฐๅฎšไน‰็š„ๆ–นๆณ•๏ผ‰. ```javascript fn(); var aaa = 111; function fn(){ //ๅ˜้‡ๅฃฐๆ˜Žๆๅ‡ๅœจๅ‡ฝๆ•ฐๅ†…้ƒจ็…งๆ ทๅฎž็”จใ€‚ //ๅ‡ฝๆ•ฐ็š„ๅฐฑ่ฟ‘ๅŽŸๅˆ™๏ผˆๅฑ€้ƒจๅ˜้‡ไฝœ็”จๅŸŸ๏ผ‰๏ผŒๆ‰“ๅฐ็š„aaaไธๆ˜ฏ111๏ผŒ่€Œๆ˜ฏ undefinedใ€‚ console.log(aaa); // undefined var aaa = 222; } ``` **้ข„่งฃๆžไผšๅˆ†ๅ—๏ผš** ๅคšๅฏน็š„ script ๆ ‡็ญพไธญๅ‡ฝๆ•ฐ้‡ๅ็š„่ฏ๏ผŒ้ข„่งฃๆžไธไผšๅ†ฒ็ชใ€‚ไนŸๅฐฑๆ˜ฏ้ข„่งฃๆž็š„ไฝœ็”จๅŸŸๆ˜ฏๆฏไธ€ไธช็š„ script ๆ ‡็ญพใ€‚ > **varๅ…ˆๆๅ‡๏ผŒfunctionๅ†ๆๅ‡๏ผš** ็คบไพ‹๏ผš ```javascript console.log(a); // ่พ“ๅ‡บaๅ‡ฝๆ•ฐไฝ“ function a() { console.log("aaaaa"); } var a = 1; console.log(a); // ่พ“ๅ‡บ1 ``` ๆ‰“ๅฐ็ฌฌไธ€ไธช็ป“ๆžœ็š„ๆ—ถๅ€™๏ผŒvarไผšๆๅ‡๏ผŒไน‹ๅŽ function ๅ†ๆๅ‡๏ผŒไฝ†ๆ˜ฏๅ‡ฝๆ•ฐaๅ’Œๅ˜้‡a้‡ๅ๏ผŒfunction็š„aๅœจๅŽ้ข่ฆ†็›–ๆŽ‰ๅ˜้‡a๏ผŒๆ‰€ไปฅ็ฌฌไธ€ไธช่พ“ๅ‡บ a ๅ‡ฝๆ•ฐไฝ“. ็ฌฌไบŒไธชๅ‰้ขvar a = 1;ๆๅ‡ไน‹ๅŽ๏ผŒ่ฟ™ไธชไฝ็ฝฎๅฐฑ็›ธๅฝ“ไบŽๅชๆœ‰ a = 1; ่ต‹ๅ€ผ๏ผŒๆ‰€ไปฅ็ฌฌไบŒไธชๆ‰“ๅฐ1. ### 6.4ใ€ๅ˜้‡ๆๅ‡ไธŽๅ‡ฝๆ•ฐๆๅ‡็š„ๆœบๅˆถ ๏ผˆๅ‚่€ƒ้“พๆŽฅ๏ผ‰https://segmentfault.com/a/1190000008568071 ๏ผˆ้žๅธธ่ฏฆ็ป†๏ผ‰ [01-jsๅ˜้‡ๆๅ‡ไธŽๅ‡ฝๆ•ฐๆๅ‡็š„่ฏฆ็ป†่ฟ‡็จ‹.md](E:\Web\github\Web\QF Phase 2\01-jsๅ˜้‡ๆๅ‡ไธŽๅ‡ฝๆ•ฐๆๅ‡็š„่ฏฆ็ป†่ฟ‡็จ‹.md) **ๆณจๆ„๏ผšES6 ไธญ็š„ let ๅฐ†ไธๅ†่ฟ›่กŒ้ข„็ผ–่ฏ‘ๆ“ไฝœใ€‚** ไธไผš่ฟ›่กŒๅ˜้‡ๆๅ‡๏ผŒไปฃ็ ๅฐ†ไปŽไธŠๅˆฐไธ‹่ฟ›่กŒๆ‰ง่กŒ๏ผŒๅœจๅ˜้‡็š„ๅฎšไน‰ไน‹ๅ‰๏ผŒๅ˜้‡็š„ไฝฟ็”จไผšๆŠฅ้”™ใ€‚ ### 6.5ใ€ๅŒฟๅๅ‡ฝๆ•ฐ ไฝœ็”จๅคง่‡ดๅฆ‚ไธ‹๏ผš ```javascript //1.็›ดๆŽฅ่ฐƒ็”จ (function (){ console.log(1); })(); //2.็ป‘ๅฎšไบ‹ไปถ document.onclick = function () { alert(1); } //3.ๅฎšๆ—ถๅ™จ setInterval(function () { console.log(444); },1000); ``` ## 7ใ€Math ๅ‡ฝๆ•ฐ ```js Math.random() // ่ฟ”ๅ›ž 0 ~ 1 ไน‹้—ด็š„้šๆœบๆ•ฐใ€‚ Math.abs(x) // ่ฟ”ๅ›žๆ•ฐ็š„็ปๅฏนๅ€ผใ€‚ Math.pow(10,2)// 10็š„2ๆฌกๆ–นใ€‚ Math.round(x) //ๆŠŠๆ•ฐๅ››่ˆไบ”ๅ…ฅไธบๆœ€ๆŽฅ่ฟ‘็š„ๆ•ดๆ•ฐใ€‚ Math.ceil(x) //ๅฏนๆ•ฐ่ฟ›่กŒไธŠ่ˆๅ…ฅใ€‚ Math.floor(x) //ๅฏนๆ•ฐ่ฟ›่กŒไธ‹่ˆๅ…ฅใ€‚ //---------------------------------------------------------------- //็คบไพ‹๏ผš console.log(Math.ceil(1.2)); // 2 console.log(Math.ceil(1.5)); // 2 console.log(Math.ceil(1.6)); // 2 console.log(Math.ceil(-1.2)); // -1 console.log(Math.ceil(-1.5)); // -1 console.log(Math.ceil(-1.6)); // -1 console.log(Math.floor(1.2)); // 1 console.log(Math.floor(1.5)); // 1 console.log(Math.floor(1.6)); // 1 console.log(Math.floor(-1.2));// -2 console.log(Math.floor(-1.5));// -2 console.log(Math.floor(-1.6));// -2 console.log(Math.round(1.2)); // 1 console.log(Math.round(1.5)); // 2 console.log(Math.round(1.6)); // 2 console.log(Math.round(-1.2)); // -1 console.log(Math.round(-1.5)); // -1 console.log(Math.round(-1.6)); // -2 ``` ### 7.1ใ€้šๆœบ็”ŸๆˆๆŸไธช่Œƒๅ›ด็š„ๆ•ดๆ•ฐ ```js var minNum = 1; var maxNum = 100; var num = Math.round(Math.random() * (maxNum - minNum)) + minNum; ``` `toFixed()` ๏ผšๆ–นๆณ•ๅฏๆŠŠ ๆ•ฐๅญ—ๅ››่ˆไบ”ๅ…ฅไธบๆŒ‡ๅฎšๅฐๆ•ฐไฝๆ•ฐ็š„ๆ•ฐๅญ—ใ€‚ ```js var num = 10; console.log(num.toFixed(2)); // 10.00 ``` ## 8ใ€ๅ‡ฝๆ•ฐไนŸๆ˜ฏๅฏน่ฑก ```js //ๅ‡ฝๆ•ฐไนŸๆ˜ฏๅฏน่ฑก function fn() {} fn.a=10; // ็ป™ๅ‡ฝๆ•ฐๅฏน่ฑกๅˆ›ๅปบไธ€ไธชๅ‚ๆ•ฐa fn.fn2=function () { // ็ป™ๅ‡ฝๆ•ฐๅฏน่ฑกๅˆ›ๅปบไธ€ไธชๅ‚ๆ•ฐfn2 return 5; }; for(var i in fn) { console..log(i); // a fn2 } //---------------------------------------- function fn1(a,b) { if(arguments.callee.length!==arguments.length){ console.log("่พ“ๅ…ฅๅ‚ๆ•ฐ้”™่ฏฏ") } // console.log(this.a);//้”™่ฏฏ็š„ console.log(arguments.callee.a);//ๅฏไปฅ่Žทๅ–ๅฝ“ๅ‰ๅ‡ฝๆ•ฐๅฏน่ฑก็š„ๅฑžๆ€งๅ’Œๆ–นๆณ• console.log(arguments.callee.fn2()); console.log(arguments.length) // 2 for(var str in arguments.callee){ console.log(str) } } fn1(3,5); // ๅ‡ฝๆ•ฐlengthๆ˜ฏๅฝขๅ‚็š„ไธชๆ•ฐ๏ผŒๅ’Œarguments.lengthไธไธ€ๅฎš็›ธๅŒ console.log(fn1.length); // 2 ``` > ๆณจๆ„๏ผš > > ๅ‡ฝๆ•ฐ.length === ๅ‡ฝๆ•ฐๅฝขๅ‚็š„ไธชๆ•ฐ > > arguments.length === ๅ‡ฝๆ•ฐๅฎžๅ‚็š„ไธชๆ•ฐ > > arguments.callee === ๅœจๅ“ชไธชๅ‡ฝๆ•ฐ้‡Œ้ขๅฐฑ่กจ็คบๅ“ชไธชๅ‡ฝๆ•ฐ๏ผˆๅฝ“ๅ‰่ฐƒ็”จๅ…ถ็š„ๅ‡ฝๆ•ฐ๏ผ‰ใ€‚ ## 9ใ€ๅ…ถไป– ### 9.1ใ€ๅ‡ฝๆ•ฐ็š„ๅฃฐๆ˜Žๅ’Œๅ‡ฝๆ•ฐ่กจ่พพๅผ็š„ๅŒบๅˆซ ```js // ๅ‡ฝๆ•ฐ็š„ๅฃฐๆ˜Ž if(true) { function f1() { console.log("f1()--1"); } } else { function f1() { console.log("f1()--2"); } } f1(); ``` > ๅ‡ฝๆ•ฐๅฃฐๆ˜Žๅฆ‚ๆžœๆ”พๅœจ if-else- ้‡Œ้ข๏ผŒ > > chrome ๅ’Œ firefox ่พ“ๅ‡บ f1()--1, > > IE8 ไธ‹่พ“ๅ‡บ f1()--2๏ผŒๅ› ไธบๅ‡ฝๆ•ฐๅฃฐๆ˜Žไผšๆๅ‰๏ผŒ็ฌฌไบŒไธชๅฐ†็ฌฌไธ€ไธช่ฆ†็›–ไบ†ใ€‚ ```js // ๅ‡ฝๆ•ฐ่กจ่พพๅผ var func; if(true) { func = function () { console.log("f1()--1"); }; } else { func = function () { console.log("f1()--2"); }; } func(); ``` > ๅ‡ฝๆ•ฐ่กจ่พพๅผ็š„ๆ–นๅผ๏ผŒ่พ“ๅ‡บ้ƒฝๆ˜ฏ f1()--1ใ€‚ๆ‰€ไปฅๅฐฝ้‡ไฝฟ็”จๅ‡ฝๆ•ฐ่กจ่พพๅผใ€‚ ### 9.2ใ€ไธฅๆ ผๆจกๅผ ```js function func() { console.log(this) // window } func(); ``` > ๆญฃๅธธๆƒ…ๅ†ตไธ‹ๆ˜ฏๆญฃ็กฎ็š„ใ€‚ ```js "use strict"; function func() { console.log(this) // window } window.func(); // ไธฅๆ ผๆจกๅผไธ‹ๅฟ…้กปๅŠ  window๏ผŒๅ› ไธบไป–่ฎคไธบๅ‡ฝๆ•ฐๆ˜ฏไธ€ไธชๆ–นๆณ•๏ผŒๆ–นๆณ•ๅฟ…้กป้€š่ฟ‡ๅฏน่ฑกๆฅ่ฐƒ็”จ็š„ใ€‚ ``` **9.2.1ใ€ๅ‡ฝๆ•ฐไนŸๆ˜ฏๅฏน่ฑก๏ผŒๅฏน่ฑกไธไธ€ๅฎšๆ˜ฏๅ‡ฝๆ•ฐ๏ผˆๆฏ”ๅฆ‚๏ผšMath๏ผ‰ใ€‚** ๅช่ฆๆœ‰ `__proto__` ็š„ๅฐฑๆ˜ฏๅฏน่ฑก๏ผ› ๅชๆœ‰่ฆ `prototype` ็š„ๅฐฑๆ˜ฏๅ‡ฝๆ•ฐ๏ผŒๅ› ไธบๅ‡ฝๆ•ฐๆ‰ไผš่ฐƒ็”จ prototype ๅฑžๆ€งใ€‚ ๅฏน่ฑกไธไธ€ๅฎšๆ˜ฏๅ‡ฝๆ•ฐ๏ผšๆฏ”ๅฆ‚ Math๏ผŒไธญๆœ‰ `__proto__` ๏ผŒไฝ†ๆ˜ฏๆฒกๆœ‰ `prototype`ใ€‚ **9.2.2ใ€ๆ‰€ๆœ‰็š„ๅ‡ฝๆ•ฐ้ƒฝๆ˜ฏ็”ฑ Function ๆž„้€ ๅ‡ฝๆ•ฐๅˆ›ๅปบ็š„ๅฎžไพ‹ๅฏน่ฑกใ€‚** ๆ—ข็„ถๅ‡ฝๆ•ฐๆ˜ฏๅฏน่ฑก๏ผŒ้‚ฃไนˆๆ˜ฏไป€ไนˆๆž„้€ ๅ‡ฝๆ•ฐๅˆ›ๅปบ็š„ๅ‘ข๏ผŸ ```js var f1 = new Function("a", "b", "return a+b"); f1(1,2); // ไธŠ้ข็›ธๅฝ“ไบŽ๏ผšๅ‡ฝๆ•ฐ็š„ๅฃฐๆ˜Ž function f1(a, b) { return a+b; } f1(1,2); // ็›ธๅฝ“ไบŽ๏ผšๅ‡ฝๆ•ฐ่กจ่พพๅผ var f1 = function (a, b) { return a+b; } f1(1,2); ``` ้‚ฃไนˆ Function ๆ˜ฏไธชไป€ไนˆไธœ่ฅฟๅ‘ข๏ผŸ ็ปๆŸฅ็œ‹ๆ˜ฏๅฏน่ฑกไนŸๆ˜ฏๅ‡ฝๆ•ฐใ€‚็„ถๅŽๆŸฅ็œ‹ๅฎƒ็š„ `__proto__` ๆŒ‡ๅ‘็š„ๆ˜ฏ Object็š„ๅŽŸๅž‹ๅฏน่ฑกใ€‚ๆ‰€ๆœ‰็š„ๅฏน่ฑกๆŒ‡ๅ‘็š„้ƒฝๆ˜ฏObject็š„ๅŽŸๅž‹ๅฏน่ฑกใ€‚
Daotin/Web/03-JavaScript/01-JavaScriptๅŸบ็ก€็Ÿฅ่ฏ†/04-ๅ‡ฝๆ•ฐ.md/0
{ "file_path": "Daotin/Web/03-JavaScript/01-JavaScriptๅŸบ็ก€็Ÿฅ่ฏ†/04-ๅ‡ฝๆ•ฐ.md", "repo_id": "Daotin", "token_count": 7365 }
12
ๆ‰“้ฃžๆœบๅฐๆกˆไพ‹ ็Žฉๆณ•๏ผš้”ฎ็›˜ไธŠไธ‹ๅทฆๅณๆ–นๅ‘้”ฎๆŽงๅˆถ้ฃžๆœบ็š„็งปๅŠจ๏ผŒๅญๅผนๆ‰“ๅˆฐๆ•Œๆœบ๏ผŒๆ•Œๆœบๆถˆๅคฑ๏ผŒ่ฎกๅˆ†ๆฟๆ˜พ็คบๆถˆ็ญๆ•Œๆœบๆ•ฐ้‡ใ€‚ ไปฃ็ ๅฆ‚ไธ‹๏ผš ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> * { margin: 0; padding: 0; } .dv { width: 300px; height: 600px; margin: 20px auto; position: relative; } .box { width: 300px; height: 500px; /* margin: 20px auto; */ border: 2px solid #666; position: relative; overflow: hidden; } .me { width: 49px; height: 61px; background: url("../images/me.png"); background-size: 49px 61px; border: 1px solid green; box-sizing: border-box; position: absolute; left: 125px; top: 439px; } .zd { width: 7px; height: 18px; background: url("../images/bullet.png"); background-size: 7px 18px; position: absolute; } .plane { width: 30px; height: 18px; background: url("../images/plane1.png"); background-size: 30px 18px; border: 1px solid red; box-sizing: border-box; position: absolute; } p { width: 300px; height: 50px; background-color: aqua; position: absolute; border: 2px solid #666; top: 500px; left: 0; } p span { color: red; font-size: 30px; } .over { width: 300px; height: 500px; background-color: rgba(0, 0, 0, 0.6); position: absolute; left: 0; top: 0; display: none; } .over span { width: 214px; height: 52px; position: absolute; background-image: url("../images/logo.png"); background-size: 214px 52px; left: 42px; top: 250px; } </style> </head> <body> <div class="dv"> <div class="box"> <div class="over"><span></span></div> <div class="me"></div> <!-- <div class="zd"></div> --> <!-- <div class="plane"></div> --> </div> <p>ไฝ ๅทฒๅ‡ป่ฝๆ•Œๆœบ&nbsp;<span>0</span>&nbsp;ๆžถ</p> </div> </body> <script src="../js/daotin.js"></script> <script> var box = document.querySelector(".box"); // console.log(box); var me = document.querySelector(".me"); var span = document.querySelector("p span"); var over = document.querySelector(".over"); var step = 5; // me ็งปๅŠจ้€Ÿๅบฆ var bulletSpeed = 20; // ๅญๅผน็งปๅŠจ้€Ÿๅบฆ var planeSpeed = 1; var bulletCreatTimer = 0; var planeCreatTimer = 0; var boxWidth = getStyle(box, "width"); var boxHeight = getStyle(box, "height"); var meWidth = parseInt(getStyle(me, "width")); var meHeight = parseInt(getStyle(me, "height")); var bulletWidth = 0; var bulletHeight = 0; var planeWidth = 0; var planeHeight = 0; // ไบง็”Ÿๅญๅผน function creatBullet() { var bullet = document.createElement("div"); bullet.className = "zd"; box.appendChild(bullet); bulletWidth = parseInt(getStyle(bullet, "width")); bulletHeight = parseInt(getStyle(bullet, "height")); bullet.style.top = parseInt(getStyle(me, "top")) - parseInt(getStyle(bullet, "height")) + "px"; bullet.style.left = parseInt(getStyle(me, "left")) + parseInt(getStyle(me, "width")) / 2 - parseInt(getStyle( bullet, "width")) / 2 + "px"; // ๆฏไธชๅญๅผน้ƒฝๆœ‰่‡ชๅทฑ็‹ฌ็ซ‹็š„ๅฎšๆ—ถๅ™จ๏ผŒๆ‰€ไปฅไฝฟ็”จbullet.timer bullet.timer = setInterval(function () { bullet.style.top = parseInt(getStyle(bullet, "top")) - bulletSpeed + "px"; var planeAll = document.querySelectorAll(".plane"); if (parseInt(bullet.style.top) <= 0) { clearInterval(bullet.timer); bullet.remove(); } // ๆฏ็”Ÿๆˆไธ€้ข—ๅญๅผน๏ผŒๅˆคๆ–ญๅญๅผนไธŽๆ•Œๆœบ็š„ไฝ็ฝฎ for (var i = 0; i < planeAll.length; i++) { var planeItem = planeAll[i]; var tmpplaneLeft = parseInt(getStyle(planeItem, "left")); var tmpplaneTop = parseInt(getStyle(planeItem, "top")); var tmpbulletLeft = parseInt(getStyle(bullet, "left")); var tmpbulletTop = parseInt(getStyle(bullet, "top")); var meLeft = parseInt(getStyle(me, "left")); var meTop = parseInt(getStyle(me, "top")); // ๆ•Œๆœบๆ’žๅˆฐไบ†ๆˆ‘ๆ–น้ฃžๆœบ๏ผŒๆธธๆˆ็ป“ๆŸ if ((tmpplaneLeft + planeWidth > meLeft) && (meLeft + meWidth > tmpplaneLeft) && (tmpplaneTop + planeHeight > meTop) && (meTop + meHeight > tmpplaneTop)) { for (var i = 0; i < planeAll.length; i++) { clearInterval(planeAll[i].timer); } document.onkeydown = document.onkeyup = null; clearInterval(bullet.timer); clearInterval(bulletCreatTimer); clearInterval(planeCreatTimer); over.style.display = "block"; } // ๅญๅผนๆ‰“ๅˆฐๆ•Œๆœบ๏ผŒๆ•Œๆœบๆถˆๅคฑ if ((tmpbulletLeft + bulletWidth > tmpplaneLeft) && (tmpplaneLeft + planeWidth > tmpbulletLeft) && (tmpbulletTop + bulletHeight > tmpplaneTop) && (tmpplaneTop + planeHeight > tmpbulletTop)) { span.innerHTML = span.innerHTML * 1 + 1; clearInterval(bullet.timer); bullet.remove(); clearInterval(planeItem.timer); planeItem.remove(); } } }, 100); }; bulletCreatTimer = setInterval(creatBullet, 200); // ไบง็”Ÿๆ•Œๆœบ function creatPlane() { var plane = document.createElement("div"); plane.className = "plane"; box.appendChild(plane); planeWidth = parseInt(getStyle(plane, "width")); planeHeight = parseInt(getStyle(plane, "height")); plane.style.left = Math.floor(Math.random() * (parseInt(getStyle(box, "width")) - parseInt(getStyle(plane, "width")))) + "px"; plane.style.top = 0; plane.timer = setInterval(function (e) { plane.style.top = parseInt(plane.style.top) + planeSpeed + "px"; if (parseInt(plane.style.top) >= (parseInt(boxHeight) - parseInt(getStyle(plane, "height")))) { clearInterval(plane.timer); plane.remove(); } }, 10); }; planeCreatTimer = setInterval(creatPlane, 1000); // ้”ฎ็›˜ๆŽงๅˆถๆˆ‘ๆ–น้ฃžๆœบ็งปๅŠจ document.onkeydown = document.onkeyup = function (e) { var evt = window.event || e; var keyCode = evt.which || evt.keyCode; switch (keyCode) { case 37: //ๅทฆ me.style.left = parseInt(getStyle(me, "left")) - step + "px"; parseInt(me.style.left) <= 0 ? me.style.left = 0 : me.style.left = me.style.left; break; case 38: //ไธŠ me.style.top = parseInt(getStyle(me, "top")) - step + "px"; parseInt(me.style.top) <= 0 ? me.style.top = 0 : me.style.top = me.style.top; break; case 39: //ๅณ me.style.left = parseInt(getStyle(me, "left")) + step + "px"; parseInt(me.style.left) >= (parseInt(boxWidth) - parseInt(meWidth)) ? me.style.left = (parseInt(boxWidth) - parseInt(meWidth)) + "px" : me.style.left = me.style.left; break; case 40: //ไธ‹ me.style.top = parseInt(getStyle(me, "top")) + step + "px"; parseInt(me.style.top) >= (parseInt(boxHeight) - parseInt(meHeight)) ? me.style.top = (parseInt(boxHeight) - parseInt(meHeight)) + "px" : me.style.top = me.style.top; break; default: break; } } </script> </html ``` ![](./images/1.gif)
Daotin/Web/03-JavaScript/02-DOM/ๆกˆไพ‹04๏ผšๆ‰“้ฃžๆœบ.md/0
{ "file_path": "Daotin/Web/03-JavaScript/02-DOM/ๆกˆไพ‹04๏ผšๆ‰“้ฃžๆœบ.md", "repo_id": "Daotin", "token_count": 4668 }
13
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> .map { width: 800px; height: 600px; background-color: #ccc; position: relative; } </style> </head> <body> <div class="map"></div> <script src="common.js"></script> <script> // ่Žทๅ–ๅœฐๅ›พๅฏน่ฑก var map = document.getElementsByClassName("map")[0]; // ไบง็”Ÿ้šๆœบๆ•ฐๅฏน่ฑก (function () { // ไบง็”Ÿ้šๆœบๆ•ฐ็š„ๆž„้€ ๅ‡ฝๆ•ฐ function Random() { } // ๆŠŠRandomๆšด้œฒ็ป™window window.Random = Random; // ๅœจๅŽŸๅž‹ๅฏน่ฑกไธญๆทปๅŠ ๆ–นๆณ• Random.prototype.getRandom = function (min, max) { // ่Œƒๅ›ด min ~ max-1 return Math.floor(Math.random() * (max - min) + min); }; }()); // ไบง็”Ÿๅฐๆ–นๅ—ๅฏน่ฑก----------------------------------------- (function () { // ไฟๅญ˜้ฃŸ็‰ฉ็š„ๆ•ฐ็ป„ var elements = []; // ้ฃŸ็‰ฉ็š„ๆž„้€ ๅ‡ฝๆ•ฐ function Food(width, height, color) { this.width = width || 20; this.height = height || 20; this.color = color || "green"; this.x = 0; // leftๅฑžๆ€ง this.y = 0; // topๅฑžๆ€ง this.element = document.createElement("div"); // ้ฃŸ็‰ฉๅฎžไพ‹ๅฏน่ฑก } // ๅฐ†Foodๆšด้œฒ็ป™window window.Food = Food; // ๅˆๅง‹ๅŒ–ๅฐๆ–นๅ—็š„ๆ˜พ็คบๆ•ˆๆžœๅŠไฝ็ฝฎ Food.prototype.init = function () { // ๆฏๆฌกๅœจๅˆ›ๅปบๅฐๆ–นๅ—ไน‹ๅ‰ๅ…ˆๅˆ ้™คไน‹ๅ‰็š„ๅฐๆ–นๅ—๏ผŒไฟ่ฏmapไธญๅชๆœ‰ไธ€ไธชๅฐๆ–นๅ— remove(); var div = this.element; map.appendChild(div); div.style.width = this.width + "px"; div.style.height = this.height + "px"; div.style.backgroundColor = this.color; div.style.position = "absolute"; this.x = new Random().getRandom(0, map.offsetWidth / this.width) * this.width; this.y = new Random().getRandom(0, map.offsetHeight / this.height) * this.height; div.style.left = this.x + "px"; div.style.top = this.y + "px"; // ๆŠŠdivๅŠ ๅˆฐๆ•ฐ็ป„ไธญ elements.push(div); }; // ็งๆœ‰ๅ‡ฝๆ•ฐ๏ผšๅˆ ้™คๅฐๆ–นๅ— function remove() { for (var i = 0; i < elements.length; i++) { elements[i].parentElement.removeChild(elements[i]); elements.splice(i, 1); // ๆธ…็ฉบๆ•ฐ็ป„๏ผŒไปŽi็š„ไฝ็ฝฎๅˆ ้™ค1ไธชๅ…ƒ็ด  } } }()); // ไบง็”Ÿๅฐ่›‡ๅฏน่ฑก------------------------------------------------------ (function () { // ๅˆ›ๅปบๆ•ฐ็ป„ไฟๅญ˜ๅฐ่›‡่บซไฝ“็š„ๆฏไธชdiv var elements = []; function Snack(width, height, direction) { // ๅฐ่›‡ๆฏไธ€ๅ—็š„ๅฎฝ้ซ˜ this.width = width || 20; this.height = height || 20; this.direction = direction || "right"; this.beforeDirection = this.direction; // ๅฐ่›‡็ป„ๆˆ่บซไฝ“็š„ๆฏไธชๅฐๆ–นๅ— this.body = [ {x: 3, y: 2, color: "red"}, {x: 2, y: 2, color: "orange"}, {x: 1, y: 2, color: "orange"} ]; } // ๅฐ†Snackๆšด้œฒ็ป™window window.Snack = Snack; // ไธบๅŽŸๅž‹ๆทปๅŠ ๅฐ่›‡ๅˆๅง‹ๅŒ–็š„ๆ–นๆณ• Snack.prototype.init = function (map) { // ๆ˜พ็คบๅฐ่›‡ไน‹ๅ‰ๅˆ ้™คๅฐ่›‡ remove(); // ๅพช็Žฏๅˆ›ๅปบๅฐ่›‡่บซไฝ“div for (var i = 0; i < this.body.length; i++) { var div = document.createElement("div"); map.appendChild(div); div.style.width = this.width + "px"; div.style.height = this.height + "px"; div.style.position = "absolute"; // ็งปๅŠจๆ–นๅ‘๏ผŒ็งปๅŠจ็š„ๆ—ถๅ€™่ฎพ็ฝฎ // ๅๆ ‡ไฝ็ฝฎ var tempObj = this.body[i]; div.style.left = tempObj.x * this.width + "px"; div.style.top = tempObj.y * this.width + "px"; div.style.backgroundColor = tempObj.color; // ๅฐ†ๅฐ่›‡ๆทปๅŠ ๅˆฐๆ•ฐ็ป„ elements.push(div); } }; // ไธบๅŽŸๅž‹ๆทปๅŠ ๅฐ่›‡็งปๅŠจๆ–นๆณ• Snack.prototype.move = function (food) { var index = this.body.length - 1; // ๅฐ่›‡่บซไฝ“็š„็ดขๅผ• // ไธ่€ƒ่™‘ๅฐ่›‡ๅคด้ƒจ for (var i = index; i > 0; i--) { // i>0 ่€Œไธๆ˜ฏ i>=0 this.body[i].x = this.body[i - 1].x; this.body[i].y = this.body[i - 1].y; } // ๅฐ่›‡ๅคด้ƒจ็งปๅŠจ switch (this.direction) { case "right" : // if(this.beforeDirection !== "left") { this.body[0].x += 1; // } break; case "left" : this.body[0].x -= 1; break; case "up" : this.body[0].y -= 1; break; case "down" : this.body[0].y += 1; break; default: break; } // ๅฐ่›‡็งปๅŠจ็š„ๆ—ถๅ€™๏ผŒๅฝ“ๅฐ่›‡ๅทๅๆ ‡ๅ’Œ้ฃŸ็‰ฉ็š„ๅๆ ‡็›ธๅŒ่กจ็คบๅƒๅˆฐ้ฃŸ็‰ฉ var headX = this.body[0].x * this.width; var headY = this.body[0].y * this.height; // ๅƒๅˆฐ้ฃŸ็‰ฉ๏ผŒๅฐ†ๅฐพๅทดๅคๅˆถไธ€ไปฝๅŠ ๅˆฐๅฐ่›‡bodyๆœ€ๅŽ if ((headX === food.x) && (headY === food.y)) { var last = this.body[this.body.length - 1]; this.body.push({ x: last.x, y: last.y, color: last.color }); // ๅˆ ้™ค้ฃŸ็‰ฉ food.init(); } }; // ็งๆœ‰ๅ‡ฝๆ•ฐ๏ผšๅˆ ้™คๅฐ่›‡ function remove() { var i = elements.length - 1; for (; i >= 0; i--) { elements[i].parentNode.removeChild(elements[i]); elements.splice(i, 1); } } }()); // ไบง็”Ÿๆธธๆˆๅฏน่ฑก---------------------------------------------------------- (function () { var that = null; function Game(map) { this.food = new Food(20, 20, "purple"); this.snack = new Snack(20, 20); this.map = map; that = this; } // ๅˆๅง‹ๅŒ–ๆธธๆˆ Game.prototype.init = function () { this.food.init(this.map); this.snack.init(this.map); this.autoRun(); this.changeDirection(); }; // ๅฐ่›‡่‡ชๅŠจ่ท‘่ตทๆฅ Game.prototype.autoRun = function () { var timeId = setInterval(function () { this.snack.move(this.food); this.snack.init(this.map); // ๅˆคๆ–ญๆœ€ๅคงX,Y่พน็•Œ var maxX = this.map.offsetWidth / this.snack.width; var maxY = this.map.offsetHeight / this.snack.height; // Xๆ–นๅ‘่พน็•Œ if ((this.snack.body[0].x < 0) || (this.snack.body[0].x >= maxX)) { // ๆ’žๅข™ไบ† clearInterval(timeId); alert("Oops, Game Over!"); } // Yๆ–นๅ‘่พน็•Œ if ((this.snack.body[0].y < 0) || (this.snack.body[0].y >= maxY)) { // ๆ’žๅข™ไบ† clearInterval(timeId); alert("Oops, Game Over!"); } }.bind(that), 150); // ไฝฟ็”จbind๏ผŒ้‚ฃไนˆinitๆ–นๆณ•ไธญๆ‰€ๆœ‰็š„this้ƒฝๅฐ†่ขซbind็š„ๅ‚ๆ•ฐthatๆ›ฟๆข }; // ๆŒ‰ไธ‹้”ฎ็›˜ๆ”นๅ˜ๅฐ่›‡็งปๅŠจๆ–นๅ‘ Game.prototype.changeDirection = function () { addAnyEventListener(document, "keydown", function (e) { // ๆฏๆฌกๆŒ‰้”ฎไน‹ๅ‰ไฟๅญ˜ๆŒ‰้”ฎๆ–นๅ‘ this.snack.beforeDirection = this.snack.direction; switch (e.keyCode) { case 37: // ๅทฆ this.snack.beforeDirection !== "right" ? this.snack.direction = "left" : this.snack.direction = "right"; break; case 38: // ไธŠ this.snack.beforeDirection !== "down" ? this.snack.direction = "up" : this.snack.direction = "down"; break; case 39: // ๅณ this.snack.beforeDirection !== "left" ? this.snack.direction = "right" : this.snack.direction = "left"; break; case 40: // ไธ‹ this.snack.beforeDirection !== "up" ? this.snack.direction = "down" : this.snack.direction = "up"; break; default: break; } }.bind(that)); }; window.Game = Game; }()); var game = new Game(map); game.init(); </script> </body> </html>
Daotin/Web/03-JavaScript/04-JavaScript้ซ˜็บง็Ÿฅ่ฏ†/ๆกˆไพ‹ๆบ็ /่ดชๅƒ่›‡/index.html/0
{ "file_path": "Daotin/Web/03-JavaScript/04-JavaScript้ซ˜็บง็Ÿฅ่ฏ†/ๆกˆไพ‹ๆบ็ /่ดชๅƒ่›‡/index.html", "repo_id": "Daotin", "token_count": 5407 }
14
ๅ‰ๆ๏ผšๆˆ‘ไปฌๅœจmysqlๅˆ›ๅปบไบ†ไธ€ไธชๆ•ฐๆฎๅบ“: mydb. mydb ้‡Œ้ขๆœ‰ไธชๆ•ฐๆฎ่กจ mytableใ€‚ mytable ไธญ็š„ๆ•ฐๆฎไธบ๏ผš | id | name | age | | ---- | ------ | ---- | | 1 | daotin | 18 | | 2 | lvonve | 19 | | 3 | li | 20 | PHPไปฃ็ ่ฟžๆŽฅๆ•ฐๆฎๅบ“mydb๏ผš ```php <?php @header("content-type:text/html;charset=utf8"); mysql_connect("localhost:3306", "root", "root"); // ๅฆ‚ๆžœๆ— ๆณ•้“พๆŽฅๅฐ†ไผšๆŠฅ้”™๏ผŒๆŠฅ้”™ไฟกๆฏๅฆ‚ไธ‹๏ผš // Warning: mysql_connect() [function.mysql-connect]: [2002] ็”ฑไบŽ็›ฎๆ ‡่ฎก็ฎ—ๆœบ็งฏๆžๆ‹’็ป๏ผŒๆ— ๆณ•่ฟžๆŽฅใ€‚ (trying to connect via tcp://localhost:33062) in $connect = mysql_select_db("mydb"); // ้€‰ๆ‹ฉ็š„ๆ•ฐๆฎๅบ“ๅญ˜ๅœจ่ฟ”ๅ›ž1๏ผŒๅฆๅˆ™ไธบ็ฉบ if($connect) { echo "ๆ•ฐๆฎๅบ“ๅญ˜ๅœจ"; } else { echo "ๆ•ฐๆฎๅบ“ไธๅญ˜ๅœจ"; } $sql = 'select * from mytable'; // ๅฎšไน‰ๆŸฅ่ฏขๆ•ฐๆฎ่กจ๏ผˆmytable๏ผ‰่ฏญๅฅ $res = mysql_query($sql); // ๆ‰ง่กŒๆ•ฐๆฎ่กจๆŸฅ่ฏข่ฏญๅฅ๏ผŒ่ฟ”ๅ›žๅ€ผๆ˜ฏresouceๆ ผๅผ็š„ๆ•ฐๆฎใ€‚ // mysql_fetch_array ๅฐ†resouceๆ ผๅผ็š„ๆ•ฐๆฎ่ฝฌๅŒ–ๆˆArrayๆ•ฐๆฎ็ฑปๅž‹ // ็”ฑไบŽmysql_fetch_arrayๆฏๆฌกๅช่ƒฝ่ฝฌๆขๆ•ฐๆฎ่กจ็š„ไธ€่กŒๆ•ฐๆฎ๏ผŒๆ‰€ไปฅ่ฆๅพช็Žฏ่ฝฌๆขใ€‚ // ไฝฟ็”จwhileๆ˜ฏๅ› ไธบๆฒกๆœ‰ๆ•ฐๆฎ็š„ๅœฐๆ–น่ฝฌๆข็š„็ป“ๆžœไธบfalse // ๆœ€ๅŽๅฐ†ๅคšไธชarrayๅŠ ๅ…ฅๆ•ฐ็ป„listไธญใ€‚ $list = array(); while($item = mysql_fetch_array($res)) { $list[] = $item; } // ไฝฟ็”จjson_encodeๅฐ†่ฝฌๆข็š„array้›†ๅˆๅ˜ๆˆjsonๅฏน่ฑก้›†ๅˆใ€‚ echo json_encode($list); ?> ``` ่Žทๅ–ๅˆฐ็š„ๆ•ฐๆฎๅฆ‚ไธ‹๏ผš ![](./images/2.png) ๆˆ‘ไปฌๅ‘็Žฐไธ€ไธช้—ฎ้ข˜๏ผšๅฐฑๆ˜ฏ่Žทๅ–ๅˆฐ็š„ๆœ‰ไธคไปฝ็›ธๅŒ็š„ๆ•ฐๆฎ๏ผŒ่ฟ™ๅฐฑ้€ ๆˆๆ•ฐๆฎ็š„ๅ†—ไฝ™๏ผŒๆ€Žไนˆ่งฃๅ†ณๅ‘ข๏ผŸ ่งฃๅ†ณๅŠžๆณ•๏ผš ๆˆ‘ไปฌ็”จๅฆไธ€ไธชๆ•ฐ็ป„ๆฅๆ”พๅ…ฅ่Žทๅ–ๅˆฐ็š„ๆ•ฐ็ป„ไธญ๏ผŒๆˆ‘ไปฌ้œ€่ฆ็š„ๆ•ฐๆฎใ€‚ ```php $list = array(); while($item = mysql_fetch_array($res)) { $tmp = array(); $tmp["id"] = $item["id"]; $tmp["name"] = $item["name"]; $tmp["age"] = $item["age"]; $tmp["status"] = $item["status"]; $list[] = $tmp; } // ไฝฟ็”จjson_encodeๅฐ†่ฝฌๆข็š„array้›†ๅˆๅ˜ๆˆjsonๅฏน่ฑก้›†ๅˆใ€‚ echo json_encode($list); ``` ไบŽๆ˜ฏๅฐฑ่Žทๅ–ๅˆฐไบ†ๆˆ‘ไปฌๆƒณ่ฆ็š„ๆ•ฐๆฎ๏ผš ![](./images/3.png) ๅพ—ๅˆฐๆ•ฐๆฎๅŽ๏ผŒๆˆ‘ไปฌๅฐฑๅฏไปฅ้€š่ฟ‡htmlไปฃ็ ๅฐ†ๅ…ถๆธฒๆŸ“ๅˆฐ้กต้ข๏ผš ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> * { margin: 0; padding: 0; } div { width: 400px; margin: 50px auto; } table { width: 400px; border: 1px solid #666; border-collapse: collapse; text-align: center; } </style> </head> <body> <div> <table border="1"> <tr> <th>็ผ–ๅท</th> <th>็”จๆˆทๅ</th> <th>ๅนด้พ„</th> <th>ๆ“ไฝœ</th> </tr> <!-- <tr> <td>1</td> <td>ๅ“ˆๅ“ˆ</td> <td>18</td> <td><a href="javascript:;">ๅˆ ้™ค</a></td> </tr> <tr> <td>2</td> <td>ๆˆ‘็š„</td> <td>18</td> <td><a href="javascript:;">ๅˆ ้™ค</a></td> </tr> --> </table> </div> </body> <script> var table = document.querySelector("table"); var xhr = new XMLHttpRequest(); xhr.open("get", "http://localhost/php/1121/connectDB.php", true); xhr.send(); xhr.onreadystatechange = function () { if (xhr.readyState == 4 && xhr.status == 200) { let list = JSON.parse(xhr.responseText); list.map(function (item) { let id = item["id"]; let uname = item["name"]; let age = item["age"]; var tr = document.createElement("tr"); var td_id = document.createElement("td"); var td_name = document.createElement("td"); var td_age = document.createElement("td"); var td_del = document.createElement("td"); var a = document.createElement("a"); a.innerHTML = "ๅˆ ้™ค"; a.href = "javascript:;"; td_id.innerHTML = id; td_name.innerHTML = uname; td_age.innerHTML = age; td_del.appendChild(a); tr.appendChild(td_id); tr.appendChild(td_name); tr.appendChild(td_age); tr.appendChild(td_del); table.appendChild(tr); a.onclick = function () { //? }; }); } }; </script> </html> ``` ![](./images/4.png) ้œ€่ฆๆณจๆ„็š„ๆ˜ฏ๏ผŒ็”ฑไบŽajaxๅ—ๅˆฐๅŒๆบ็ญ–็•ฅ็š„ๅฝฑๅ“๏ผŒๆ‰€ไปฅๆˆ‘ไปฌ็š„htmlไปฃ็ ไธ€ๅฎšๅ’Œphpๆ–‡ไปถๅœจ็›ธๅŒ็š„ๅ่ฎฎ๏ผŒ็›ธๅŒ็š„ๅŸŸๅ๏ผŒ็›ธๅŒ็š„็ซฏๅฃไธ‹ใ€‚ ๅฅฝไบ†๏ผŒไธŠ้ข็š„ไปฃ็ ่ฟ˜ๆœ‰ไธ€ไธช้—ฎ้ข˜๏ผŒๅฐฑๆ˜ฏๆˆ‘ไปฌๅœจ็‚นๅ‡ปๅˆ ้™ค็š„ๆ—ถๅ€™๏ผŒ้œ€่ฆๅฐ†ๆ•ฐๆฎๅบ“็š„ๅฏนๅบ”็š„ๆ•ฐๆฎๅˆ ้™คๅ—๏ผŸ ไธ้œ€่ฆ๏ผŒไธ€่ˆฌๆญฃๅธธ็š„ๆ“ไฝœๆ˜ฏๆฏไธชๆ•ฐๆฎ้ƒฝๅฏนๅบ”ไธ€ไธชstatus๏ผŒ่กจ็คบๆ˜ฏๅฆๅฏไปฅ่ฎฟ้—ฎ๏ผŒๆˆ‘ไปฌไปฅstatus=1ๅฏไปฅ่ฎฟ้—ฎ๏ผŒstatus=0ไธๅฏไปฅ่ฎฟ้—ฎไธบไพ‹๏ผŒๆฅๅฎž็Žฐๅˆ ้™คๆ“ไฝœใ€‚ ๆ‰€ไปฅๆˆ‘ไปฌๆ•ฐๆฎๅบ“็š„ๆ•ฐๆฎ็Žฐๅœจๆ˜ฏไธ‹้ข็š„ๆ ทๅญ๏ผš ![](./images/5.png) ๆˆ‘ไปฌphpไปฃ็ ไนŸ่ฆไฟฎๆ”นไธ‹๏ผš
Daotin/Web/05-PHP&ๆ•ฐๆฎๅบ“/04-PHP่ฟžๆŽฅmysqlๆ•ฐๆฎๅบ“.md/0
{ "file_path": "Daotin/Web/05-PHP&ๆ•ฐๆฎๅบ“/04-PHP่ฟžๆŽฅmysqlๆ•ฐๆฎๅบ“.md", "repo_id": "Daotin", "token_count": 3243 }
15
// Stacked Icons // ------------------------- .@{fa-css-prefix}-stack { position: relative; display: inline-block; width: 2em; height: 2em; line-height: 2em; vertical-align: middle; } .@{fa-css-prefix}-stack-1x, .@{fa-css-prefix}-stack-2x { position: absolute; left: 0; width: 100%; text-align: center; } .@{fa-css-prefix}-stack-1x { line-height: inherit; } .@{fa-css-prefix}-stack-2x { font-size: 2em; } .@{fa-css-prefix}-inverse { color: @fa-inverse; }
Daotin/Web/07-็งปๅŠจWebๅผ€ๅ‘/ๆกˆไพ‹ๆบ็ /03-ๅพฎ้‡‘ๆ‰€/lib/font-awesome-4.7.0/less/stacked.less/0
{ "file_path": "Daotin/Web/07-็งปๅŠจWebๅผ€ๅ‘/ๆกˆไพ‹ๆบ็ /03-ๅพฎ้‡‘ๆ‰€/lib/font-awesome-4.7.0/less/stacked.less", "repo_id": "Daotin", "token_count": 201 }
16
## ไธ€ใ€let **ไฝœ็”จ๏ผšไธŽvar็ฑปไผผ, ็”จไบŽๅฃฐๆ˜Žไธ€ไธชๅ˜้‡ใ€‚** **letๅ’Œvar็š„ๅŒบๅˆซ๏ผš** - ๅœจๅ—ไฝœ็”จๅŸŸๅ†…ๆœ‰ๆ•ˆ(ๅช่ฆๆœ‰{}ๅ‡บ็Žฐ ๅˆ™ๅชๅœจ่ฏฅ{}่Œƒๅ›ดๅ†…็”Ÿๆ•ˆ) - ไธ่ƒฝ้‡ๅคๅฃฐๆ˜Ž - ไธไผš้ข„ๅค„็†, ไธๅญ˜ๅœจๆๅ‡ ```html <script type="text/javascript"> console.log(res); //ไธไผš้ข„ๅค„็†, ไธๅญ˜ๅœจๆๅ‡๏ผŒๆŠฅ้”™ // ไธ่ƒฝ้‡ๅคๅฃฐๆ˜Ž let res = 10; let res = 10; // ๆŠฅ้”™ </script> ``` **ๅบ”็”จ๏ผšๅพช็Žฏ้ๅŽ†ๅŠ ็›‘ๅฌ** ๆˆ‘ไปฌๅ…ˆๅผ€็œ‹ไธ€ไธชไพ‹ๅญ๏ผš ```html <body> <button>ๆต‹่ฏ•1</button> <button>ๆต‹่ฏ•2</button> <button>ๆต‹่ฏ•3</button> <script type="text/javascript"> let btns = document.getElementsByTagName('button'); for (var i = 0; i < btns.length; i++) { btns[i].onclick = function () { alert(i); } } </script> </body> ``` ๆˆ‘ไปฌๅˆ†ๅˆซ็‚นๅ‡ปๆŒ‰้’ฎ็š„ๆ—ถๅ€™๏ผŒๅˆ†ๅˆซๆ‰“ๅฐๅคšๅฐ‘๏ผŸ ็ป“ๆžœ๏ผšๆ‰“ๅฐ็š„้ƒฝๆ˜ฏ2ใ€‚**ๅ› ไธบๅ›ž่ฐƒๅ‡ฝๆ•ฐ็š„ๅ†™ๆณ•ไผš่ฟ›่กŒ่ฆ†็›–ๆ“ไฝœ**ใ€‚ๅฆ‚ไฝ•่งฃๅ†ณ๏ผŸ **ๆ–นๆณ•ไธ€๏ผšไฝฟ็”จ้—ญๅŒ…ใ€‚** ```js for (var i = 0; i < btns.length; i++) { (function(){ btns[i].onclick = function () { alert(i); } })(i); } ``` ่ฟ™็งๆ–นๅผ็›ธๅฝ“ไบŽ๏ผŒๆฏไธชๅ›ž่ฐƒๅ‡ฝๆ•ฐๆœ‰ไธช่‡ชๅทฑ็š„ๅŒบ้—ด๏ผŒๅ„ไธชๅŒบ้—ดไบ’ไธๅนฒๆ‰ฐใ€‚่€Œ let ๆญฃๅฅฝๆœ‰่ฟ™ไธช็‰นๆ€งใ€‚ **ๆ–นๆณ•ไบŒ๏ผšๅฐ† forๅพช็Žฏ็š„ varๆ”นไธบletๅณๅฏใ€‚** ## ไบŒใ€const ไฝœ็”จ๏ผšๅฎšไน‰ไธ€ไธชๅธธ้‡ใ€‚ ็‰น็‚น๏ผš - ไธ่ƒฝไฟฎๆ”น - (ๅธธ้‡ๅไปŽ่ง„่ŒƒไธŠๆฅๅฐ† ๆœ€ๅฅฝๆ‰€ๆœ‰ๅญ—ๆฏๅคงๅ†™) - ๅ…ถๅฎƒ็‰น็‚นๅŒletใ€‚ ```js const uName = 'Daotin'; ``` ## ไธ‰ใ€ๅ˜้‡็š„่งฃๆž„่ต‹ๅ€ผ ็†่งฃ๏ผšไปŽๅฏน่ฑกๆˆ–ๆ•ฐ็ป„ไธญๆๅ–ๆ•ฐๆฎ, ๅนถ่ต‹ๅ€ผ็ป™ๅ˜้‡(ๅคšไธช)ใ€‚ ### 1ใ€ๅฏน่ฑก็š„่งฃๆž„่ต‹ๅ€ผ ไน‹ๅ‰ๆˆ‘ไปฌ่ฆ่Žทๅ–ไธ€ไธชๅฏน่ฑก็š„ๅฑžๆ€ง๏ผŒไผšๅฎšไน‰ๅ˜้‡็„ถๅŽๆŽฅๆ”ถๅฏน่ฑก็š„ๅฑžๆ€งๅ€ผใ€‚ ```js let obj = {name : 'kobe', age : 39}; let name = obj.name; let age = obj.age; console.log(name, age); ``` ๅฏน่ฑก็š„่งฃๆž„่ต‹ๅ€ผๅฏไปฅ่ฟ™ๆ ทๅš๏ผš ```js let {name, age} = obj; console.log(name, age); // name ๅฐฑๆ˜ฏobj.name๏ผŒageๅฐฑๆ˜ฏobj.age ``` ็ป™ๅฏน่ฑก็š„่งฃๆž„่ต‹ๅ€ผ**่ตทไธชๅˆซๅ**๏ผš ```js let obj = {name:'daotin', age:18}; let {name:myname, age:myage} = obj; // ็ป™nameๅ’Œageๅˆ†ๅˆซ่ตทไธชๅˆซๅmynameๅ’Œmyage ``` **ๆŒ‡ๅฎš้ป˜่ฎคๅ€ผ**๏ผˆๅฏนไบŽๅฏน่ฑกไธๅญ˜ๅœจ็š„ๅฑžๆ€ง๏ผŒๅฏไปฅๆทปๅŠ ้ป˜่ฎคๅ€ผ๏ผ‰๏ผš ```js let obj = {name:'daotin', age:18}; let {name,age,sex='man'} = obj; // ็ป™ๅฎšobjๅฏน่ฑกไธ€ไธชๅฑžๆ€ง้ป˜่ฎคๅ€ผ ``` > ๆณจๆ„๏ผš > 1ใ€ๅฏน่ฑก็š„่งฃๆž„่ต‹ๅ€ผๅฟ…้กปไฝฟ็”จๅคงๆ‹ฌๅท {} > > 2ใ€ๅคงๆ‹ฌๅท้‡Œ้ข็š„ๅ˜้‡ๅๅฟ…้กปๅ’Œobj้‡Œ้ข็š„ๅฑžๆ€งๅ็›ธๅŒ > > 3ใ€ๅฏไปฅๅชๅฎšไน‰ไธ€้ƒจๅˆ†ๅ˜้‡ๆŽฅๆ”ถไธ€้ƒจๅˆ†็š„objๅฑžๆ€ง๏ผŒไธ้œ€่ฆๅ…จ้ƒจๆŽฅๆ”ถใ€‚ ### 2ใ€ๆ•ฐ็ป„็š„่งฃๆž„่ต‹ๅ€ผ ๆ•ฐ็ป„ๆฒกๆœ‰ๅฏน่ฑก็š„ๆ•ฐ็ป„ๅ๏ผŒไฝ†ๆ˜ฏๆœ‰ไธ‹ๆ ‡ๅฏไปฅไฝฟ็”จใ€‚ๆ‰€ไปฅ่ฟ™้‡Œ็š„ๅ˜้‡ๅๅฏไปฅ้šไพฟ่ตทใ€‚ ```js let arr = ['abc', 23, true]; let [a, b, c] = arr; console.log(a, b, c); ``` > ๆณจๆ„๏ผš > > 1ใ€ๆ•ฐ็ป„็š„่งฃๆž„่ต‹ๅ€ผๅฟ…้กปไฝฟ็”จไธญๆ‹ฌๅท []๏ผŒๅนถไธ”ๅฏน้กบๅบๆœ‰่ฆๆฑ‚ใ€‚ > > 2ใ€ๅฏไปฅ็ป™ๅฎš้ป˜่ฎคๅ€ผ **ๅฆ‚ๆžœๅชๆƒณๅ–ๅ…ถไธญ็š„ๆŸๅ‡ ไธชๅ€ผ๏ผŒ้‚ฃไนˆๅ˜้‡ๅฏไปฅไฝฟ็”จ้€—ๅท้š”ๅผ€ใ€‚** `let [,,a,,] = arr;` **ๅฆ‚ๆžœๅฎšไน‰็š„ๅ˜้‡ไธชๆ•ฐๆฏ”ๆ•ฐ็ป„็š„ไธชๆ•ฐๅคš๏ผŒๅคšๅ‡บๆฅ็š„ๅ˜้‡็š„ๅ€ผไธบ** `undefined`ใ€‚ ## ๅ››ใ€ๆจกๆฟๅญ—็ฌฆไธฒ ไฝœ็”จ๏ผš็ฎ€ๅŒ–ๅญ—็ฌฆไธฒ็š„ๆ‹ผๆŽฅใ€‚ ๆณจๆ„๏ผš 1ใ€ๆจกๆฟๅญ—็ฌฆไธฒๅฟ…้กป็”จ ``` ` ๅŒ…ๅซ๏ผ› 2ใ€ๅ˜ๅŒ–็š„้ƒจๅˆ†ไฝฟ็”จ`${xxx}`ๅฎšไน‰ ```js let obj = { name: 'anverson', age: 41 }; // ๆˆ‘ไปฌไน‹ๅ‰ๆ‹ผๆŽฅๅญ—็ฌฆไธฒ็”จ็š„ๆ˜ฏ+ console.log('ๆˆ‘ๅซ:' + obj.name + ', ๆˆ‘็š„ๅนด้พ„ๆ˜ฏ๏ผš' + obj.age); // ไฝฟ็”จๆจกๆฟๅญ—็ฌฆไธฒ็š„ๆ–นๅผ console.log(`ๆˆ‘ๅซ:${obj.name}, ๆˆ‘็š„ๅนด้พ„ๆ˜ฏ๏ผš${obj.age}`); ``` ## ไบ”ใ€ๅฏน่ฑก็š„็ฎ€ๅŒ–ๅ†™ๆณ• ๅฆ‚ๆžœๆœ‰ๅ˜้‡ๅ’Œๅฏน่ฑก็š„ๅฑžๆ€งๅ็งฐ็›ธๅŒ๏ผŒไน‹ๅ‰็š„ๅ†™ๆณ•ๆ˜ฏ่ต‹ๅ€ผๆ“ไฝœ๏ผš ```js let a = 1; let b = 2; let Obj = { a: a, b: b, }; ``` ็Žฐๅœจ๏ผŒๅฆ‚ๆžœๅ˜้‡ๅ’Œๅฏน่ฑก็š„ๅฑžๆ€งๅ็งฐ็›ธๅŒ๏ผŒๅฏไปฅ็ฎ€ๅ†™ๅฆ‚ไธ‹๏ผš ```js let a = 1; let b = 2; let Obj = { a, b, }; ``` ๅฏนไบŽๅฏน่ฑก็š„ๅฑžๆ€ง๏ผŒๅฆ‚ๆžœๆ˜ฏไธชๅ‡ฝๆ•ฐ็š„่ฏ๏ผŒไนŸๅฏไปฅ็ฎ€ๅ†™๏ผš ไน‹ๅ‰็š„ๅ†™ๆณ•ไธบ๏ผš ```js let Obj = { foo: function(){ //... } }; ``` ็Žฐๅœจ็š„ๅ†™ๆณ•ไธบ๏ผš๏ผˆๅŽปๆŽ‰ๅ†’ๅทๅ’Œfunction๏ผ‰ ```js let Obj = { foo(){ //... } }; ``` ## ๅ…ญใ€็ฎญๅคดๅ‡ฝๆ•ฐ ไฝœ็”จ๏ผš**็ฎญๅคดๅ‡ฝๆ•ฐ็š„ไฝœ็”จไธป่ฆๆ˜ฏๅฎšไน‰ๅŒฟๅๅ‡ฝๆ•ฐใ€‚** ๆœ‰ไธ‹้ขๅ‡ ็งๆƒ…ๅ†ต็š„ๅŒฟๅๅ‡ฝๆ•ฐ้ƒฝๅฏไปฅไฝฟ็”จ็ฎญๅคดๅ‡ฝๆ•ฐ๏ผš ```js let foo = function () {}; // ่ฝฌๆขๆˆ็ฎญๅคดๅ‡ฝๆ•ฐ let foo = () => {}; //------------------------------ let Obj = { foo: function () { } } // ่ฝฌๆขๆˆ็ฎญๅคดๅ‡ฝๆ•ฐ let Obj = { foo: () => { } } ``` ๅŸบๆœฌ่ฏญๆณ•**๏ผˆๅ‚ๆ•ฐ๏ผ‰**๏ผš 1ใ€ๅŒฟๅๅ‡ฝๆ•ฐๆฒกๆœ‰ๅ‚ๆ•ฐ๏ผš() ไธ่ƒฝ็œ็•ฅ๏ผŒๅ ไฝไฝœ็”จใ€‚`let foo = () => {};` 2ใ€ๅชๆœ‰ไธ€ไธชๅ‚ๆ•ฐ๏ผš() ๅฏไปฅ็œ็•ฅ๏ผŒไนŸๅฏไปฅไธ็œ็•ฅใ€‚`let foo = a => {};` 3ใ€ๅคšไธชๅ‚ๆ•ฐ๏ผŒ() ไธ่ƒฝ็œ็•ฅใ€‚`let foo = (a,b) => {};` ๅŸบๆœฌ่ฏญๆณ•**๏ผˆๅ‡ฝๆ•ฐไฝ“๏ผ‰**๏ผš 1ใ€ๅ‡ฝๆ•ฐไฝ“ๅชๆœ‰ไธ€ๆก่ฏญๅฅ๏ผšๅฏไปฅ็œ็•ฅ{}๏ผŒๅนถไธ”้ป˜่ฎค่ฟ”ๅ›ž็ป“ๆžœ๏ผˆไธ้œ€่ฆ return๏ผ‰ใ€‚ ```js let foo = (x, y) => x + y; console.log(foo(1, 2)); ``` 2ใ€ๅ‡ฝๆ•ฐไฝ“ๅฆ‚ๆžœๆœ‰ๅคšไธช่ฏญๅฅ, ้œ€่ฆ็”จ{}ๅŒ…ๅ›ด๏ผŒ่‹ฅๆœ‰้œ€่ฆ่ฟ”ๅ›ž็š„ๅ†…ๅฎน๏ผŒ้œ€่ฆๆทปๅŠ returnใ€‚ ```js let foo = (x, y) => { console.log(x, y); return x + y; }; console.log(foo(1, 2)); ``` **็ฎญๅคดๅ‡ฝๆ•ฐ็š„็‰น็‚น๏ผš** 1ใ€ไธ่ƒฝๅšๆž„้€ ๅ‡ฝๆ•ฐ๏ผˆไธ่ƒฝๅฎžไพ‹ๅŒ–๏ผ‰ 2ใ€ๆฒกๆœ‰ arguments **3ใ€็ฎญๅคดๅ‡ฝๆ•ฐๆฒกๆœ‰่‡ชๅทฑ็š„this๏ผŒ็ฎญๅคดๅ‡ฝๆ•ฐ็š„thisไธๆ˜ฏ่ฐƒ็”จ็š„ๆ—ถๅ€™ๅ†ณๅฎš็š„๏ผŒthisๆŒ‡ๅ‘ไธŠไธ‹ๆ–‡็Žฏๅขƒใ€‚๏ผˆๆ„ๆ€๏ผš็ฎญๅคดๅ‡ฝๆ•ฐ็š„ๅค–ๅฑ‚็š„ๆ˜ฏๅฆๆœ‰ๅ‡ฝๆ•ฐ๏ผŒๅฆ‚ๆžœๆœ‰๏ผŒ็ฎญๅคดๅ‡ฝๆ•ฐ็š„thisๅฐฑๆ˜ฏๅค–ๅฑ‚ๅ‡ฝๆ•ฐ็š„this๏ผŒๅฆ‚ๆžœๆฒกๆœ‰๏ผŒๅˆ™ไธบ window๏ผ‰** > ็ฎ€ๅ•ๆ–นๆณ•๏ผš็ฎญๅคดๅ‡ฝๆ•ฐ๏ผŒthisๅฐฑๅพ€ๅค–ๆŒชไธ€ๅฑ‚๏ผŒๅค–้ขๅฆ‚ๆžœ่ฟ˜ๆ˜ฏ็ฎญๅคดๅ‡ฝๆ•ฐ๏ผŒ็ปง็ปญๅพ€ๅค–ๆŒช๏ผŒ็›ดๅˆฐๆฒกๆœ‰็ฎญๅคดๅ‡ฝๆ•ฐ็š„ๅœฐๆ–นๅฐฑๆ˜ฏๅฝ“ๅ‰this็š„ๆŒ‡ๅ‘ใ€‚ ```html <script type="text/javascript"> let foo = () => { console.log(this); }; foo(); // window ๅฏน่ฑก let Obj1 = { bar() { let foo = () => { console.log(this); }; foo(); } }; Obj1.bar(); // Obj1 ๅฏน่ฑก๏ผŒ็ฎญๅคดๅ‡ฝๆ•ฐๅค–ๅฑ‚ๆœ‰ๅ‡ฝๆ•ฐbar๏ผŒbar้‡Œ้ข็š„thisๆ˜ฏObj1. let Obj2 = { bar: () => { let foo = () => { console.log(this); }; foo(); } }; Obj2.bar(); // window ๅฏน่ฑก๏ผŒ็ฎญๅคดๅ‡ฝๆ•ฐๅค–ๅฑ‚ๆœ‰ๅ‡ฝๆ•ฐbar๏ผŒbarๅ‡ฝๆ•ฐไนŸๆ˜ฏ็ฎญๅคดๅ‡ฝๆ•ฐ๏ผŒbar็š„ๅค–ๅฑ‚ๆฒกๆœ‰ๅ‡ฝๆ•ฐ๏ผŒๆ‰€ไปฅbar้‡Œ้ข็š„thisๆ˜ฏwindow๏ผŒๆ‰€ไปฅfoo้‡Œ้ข็š„thisไนŸๆ˜ฏwindowใ€‚ </script> ``` ## ไธƒใ€ๅฑ•ๅผ€็ฌฆ/ไธ‰็‚น่ฟ็ฎ—็ฌฆ **ไฝœ็”จ๏ผš** **1ใ€็”จๆฅๅ–ไปฃ arguments ไฝ†ๆฏ” arguments ็ตๆดป,** arguments ๆ˜ฏไธชไผชๆ•ฐ็ป„๏ผŒไฝ†ๆ˜ฏไธ‰็‚น่ฟ็ฎ—็ฌฆๆ˜ฏ**็œŸๆ•ฐ็ป„**๏ผŒๅฏไปฅไฝฟ็”จ forEach ็ญ‰ๆ–นๆณ•ใ€‚ ![](./images/9.png) 2ใ€ไธ‰็‚น๏ผˆๅฏๅ˜ๅ‚ๆ•ฐ๏ผ‰่ฟ็ฎ—็ฌฆๅช่ƒฝๆ˜ฏ**ๆœ€ๅŽ้ƒจๅˆ†ๅฝขๅ‚ๅ‚ๆ•ฐใ€‚** ไฝ†ๆ˜ฏๅ‰้ขๆ˜ฏๅฏไปฅๆœ‰ๅ‚ๆ•ฐๆฅๅ ไฝ็š„ใ€‚ ![](./images/11.png) **3ใ€ๆ‰ฉๅฑ•่ฟ็ฎ—็ฌฆ** ```js let arr = [1, 6]; let arr1 = [2, 3, 4, 5]; arr = [1, ...arr1, 6]; console.log(arr); // [1,2,3,4,5,6] console.log(...arr); // 1 2 3 4 5 6 ``` ่ฏญๆณ•๏ผš`...ๆ•ฐ็ป„ๅ` ๏ผš่กจ็คบ้ๅŽ†ๆ•ฐ็ป„็š„ๆ‰€ๆœ‰ๅ…ƒ็ด ใ€‚ ## ๅ…ซใ€ๅฝขๅ‚้ป˜่ฎคๅ€ผ ไฝœ็”จ๏ผšๅฝ“ไธไผ ๅ…ฅๅ‚ๆ•ฐ็š„ๆ—ถๅ€™้ป˜่ฎคไฝฟ็”จๅฝขๅ‚้‡Œ็š„้ป˜่ฎคๅ€ผใ€‚ ```html <script type="text/javascript"> //ๅฎšไน‰ไธ€ไธช็‚น็š„ๅๆ ‡ function Point(x = 12, y = 12) { // ๅฝขๅ‚็š„้ป˜่ฎคๅ€ผ this.x = x; this.y = y; } let p = new Point(); console.log(p); let point = new Point(25, 36); console.log(point); </script> ```
Daotin/Web/08-ES6่ฏญๆณ•/03-let๏ผŒconst๏ผŒ่งฃๆž„่ต‹ๅ€ผ๏ผŒๆจกๆฟๅญ—็ฌฆไธฒ๏ผŒๅฏน่ฑก็ฎ€ๅŒ–๏ผŒ็ฎญๅคดๅ‡ฝๆ•ฐ๏ผŒไธ‰็‚น่ฟ็ฎ—็ฌฆ๏ผŒๅฝขๅ‚้ป˜่ฎคๅ€ผ.md/0
{ "file_path": "Daotin/Web/08-ES6่ฏญๆณ•/03-let๏ผŒconst๏ผŒ่งฃๆž„่ต‹ๅ€ผ๏ผŒๆจกๆฟๅญ—็ฌฆไธฒ๏ผŒๅฏน่ฑก็ฎ€ๅŒ–๏ผŒ็ฎญๅคดๅ‡ฝๆ•ฐ๏ผŒไธ‰็‚น่ฟ็ฎ—็ฌฆ๏ผŒๅฝขๅ‚้ป˜่ฎคๅ€ผ.md", "repo_id": "Daotin", "token_count": 4733 }
17
## asyncๆจกๅ—ไป‹็ป *Async is a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript. Although originally designed for use with Node.js and installable via npm install --save async, it can also be used directly in the browser.* asyncๆ˜ฏไธ€ไธชๅฎž็”จ็š„ๆจกๅ—๏ผŒๅฏนไบŽๅค„็†ๅผ‚ๆญฅjavascriptๆฅ่ฏด๏ผŒๅฎƒๅฏไปฅๆไพ›็ฎ€ไป‹ๅผบๅคง็š„ๅŠŸ่ƒฝใ€‚่™ฝ็„ถๆœ€ๅˆ่ฎพ่ฎก็š„ๆ—ถๅ€™่ง†ไธบNodejs่ฎพ่ฎก็š„๏ผŒๅฏไปฅ้€š่ฟ‡`npm install --save async` ๆฅๅผ•ๅ…ฅasyncๆจกๅ—๏ผŒไฝ†ๆ˜ฏ็ŽฐๅœจๅฎƒไนŸๅฏไปฅ่ขซ็›ดๆŽฅ็”จๅœจๆต่งˆๅ™จไธญ๏ผŒไนŸๅฐฑๆ˜ฏๅ‰็ซฏjsไปฃ็ ไธญใ€‚ ## asyncไธ‰ไธชๆจกๅผ async็š„ๅผ‚ๆญฅๆต็จ‹็ฎก็†ไธป่ฆๅˆ†ไธบไธ‰ไธชๆจกๅผ๏ผš - ๅนถ่กŒๆ— ๅ…ณ่” - ไธฒ่กŒๆ— ๅ…ณ่” - ไธฒ่กŒๆœ‰ๅ…ณ่” ### ๅนถ่กŒๆ— ๅ…ณ่” parallel ```js const async = require("async"); /** * ๅนถ่กŒๆ— ๅ…ณ่” * ่ฏญๆณ•๏ผšasync.parallel([],(err,data)=>{}) * ๅ‚ๆ•ฐ1๏ผšๅฏไปฅๆ˜ฏไธชๅฏน่ฑกๆˆ–่€…ๆ•ฐ็ป„ * ๅฆ‚ๆžœๆ˜ฏๆ•ฐ็ป„๏ผšๅ†…ๅฎนไธบไธ€็ณปๅˆ—ๅŒฟๅๅ‡ฝๆ•ฐ้›†ๅˆ๏ผŒๅŒฟๅๅ‡ฝๆ•ฐ็š„ๅ‚ๆ•ฐไธบไธ€ไธชๅ›ž่ฐƒๅ‡ฝๆ•ฐ * ๅฆ‚ๆžœๆ˜ฏๅฏน่ฑก๏ผšๅ†…ๅฎนไธบไธ€็ณปๅˆ—ๅฑžๆ€งๅ€ผไธบๅŒฟๅๅ‡ฝๆ•ฐ็ป„ๆˆ๏ผŒๅŒฟๅๅ‡ฝๆ•ฐ็š„ๅ‚ๆ•ฐไธบไธ€ไธชๅ›ž่ฐƒๅ‡ฝๆ•ฐ * * ๅ›ž่ฐƒๅ‡ฝๆ•ฐ็š„็ฌฌไธ€ไธชๅ‚ๆ•ฐ๏ผšๅนถ่กŒไปปๅŠกๆ‰ง่กŒๅคฑ่ดฅ็š„้”™่ฏฏไฟกๆฏ * ็ฌฌไบŒไธชๅ‚ๆ•ฐ๏ผšๅค„็†็š„ๆ•ฐๆฎ * * async.parallel ็ฌฌไบŒไธชๅ‚ๆ•ฐไธญ็š„dataๆ˜ฏๆ‰€ๆœ‰ๅนถ่กŒไปปๅŠกๆ‰ง่กŒๅฎŒๆˆๅŽ๏ผŒๆฑ‡่šๆˆ็š„้›†ๅˆ */ console.time("time"); // ๅ‚ๆ•ฐไธบๆ•ฐ็ป„ async.parallel([ (cb) => { setTimeout(() => { cb(null, "daotin"); }, 2000); }, (cb) => { setTimeout(() => { cb(null, "lvonve"); }, 1000); } ], (err, data) => { if (!err) { console.timeEnd("time"); // time: 2001.771ms console.log(data); // ['daotin', 'lvonve'] } }); // ๅ‚ๆ•ฐไธบๅฏน่ฑก // ๆœ€ๅŽ่Žทๅ–ๅˆฐ็š„dataไนŸๆ˜ฏๅฏน่ฑก๏ผŒๅฑžๆ€งๅๅฐฑๆ˜ฏๅ‰้ข็š„ๅฑžๆ€งๅใ€‚ console.time("time"); async.parallel({ one(cb) { setTimeout(() => { cb(null, "123"); }, 2000); }, two(cb) { setTimeout(() => { cb(null, "123"); }, 2000); } }, (err, data) => { console.timeEnd("time"); // time: 2004.775ms if (!err) { console.log(data); //{ one: '123', two: '123' } } }); ``` ### ไธฒ่กŒๆ— ๅ…ณ่” series ```js console.time("time"); console.time("time1"); async.series({ one(cb) { setTimeout(() => { cb(null, "123"); }, 2000); }, two(cb) { console.timeEnd("time1"); //time1: 2004.965ms setTimeout(() => { cb(null, "456"); }, 1000); } }, (err, data) => { console.timeEnd("time"); // time: 3010.950ms if (!err) { console.log(data); //{ one: '123', two: '456' } } }); ``` ๅฏไปฅ็œ‹ๅˆฐ๏ผŒ้™คไบ†ๅ…ณ้”ฎ่ฏ`series`ๅ˜ไบ†ไน‹ๅค–๏ผŒๆ ผๅผ้ƒฝไธ€ๆ ท๏ผŒๅชไธ่ฟ‡ๅทฒๆ˜ฏไธฒ่กŒไบ†ใ€‚ ### ไธฒ่กŒๆœ‰ๅ…ณ่” waterfall > ๆณจๆ„๏ผšไธฒ่กŒๆœ‰ๅ…ณ่”็š„็ฌฌไธ€ไธชๅ‚ๆ•ฐๅฟ…้กปๆ˜ฏๆ•ฐ็ป„๏ผŒไธ่ƒฝๆ˜ฏๅฏน่ฑก > > ๆ•ฐ็ป„ไธญ็ฌฌไธ€ไธชไปปๅŠก็š„ๅ›ž่ฐƒๅ‡ฝๆ•ฐcb็š„็ฌฌไบŒไธชๅ‚ๆ•ฐๅผ€ๅง‹ๆ˜ฏไผ ็ป™ไธ‹ไธ€ไธชไปปๅŠก็š„ๅฎžๅ‚ใ€‚ > > ็ฌฌไบŒไธชไปปๅŠกๅ‡ฝๆ•ฐๅฝขๅ‚ๅ‰ๅ‡ ไธชๅฐฑๆ˜ฏไธŠไธ€ไธชไผ ไธ‹ๆฅ็š„ๅฎžๅ‚๏ผŒ่ฟ™้‡Œๆ˜ฏnameๅฝขๅ‚ๅฏนๅบ”โ€˜daotinโ€™ๅฎžๅ‚ใ€‚ ```js console.time("time"); console.time("time1"); async.waterfall([ cb => { setTimeout(() => { cb(null, 'daotin'); }, 2000); }, (name, cb) => { console.timeEnd('time1'); // time1: 2004.008ms setTimeout(() => { cb(null, 'lvonve-' + name); }, 1000); } ], (err, data) => { console.timeEnd("time"); // time: 3008.387ms if (!err) { console.log(data); //lvonve-daotin } }); ```
Daotin/Web/10-Node.js/06-ๆ‰ฉๅฑ•async.md/0
{ "file_path": "Daotin/Web/10-Node.js/06-ๆ‰ฉๅฑ•async.md", "repo_id": "Daotin", "token_count": 2056 }
18
## ไธ€ใ€fluxๆžถๆž„ ไป€ไนˆๆ˜ฏflux๏ผŸ ็ฎ€ๅ•่ฏด๏ผŒFlux ๆ˜ฏไธ€็งๆžถๆž„ๆ€ๆƒณ๏ผŒไธ“้—จ่งฃๅ†ณ่ฝฏไปถ็š„็ป“ๆž„้—ฎ้ข˜ใ€‚ ไธ€่ˆฌ**ไธญๅคงๅž‹react้กน็›ฎ**ไผš็”จๅˆฐ Flux๏ผŒไพฟไบŽ็ฎก็†ๆ•ฐๆฎๆจกๅž‹ใ€‚ๅฐๅž‹้กน็›ฎๅฐฑๆฒกๅฟ…่ฆไฝฟ็”จไบ†ใ€‚ ### 1ใ€ๅŸบๆœฌๆฆ‚ๅฟต ้ฆ–ๅ…ˆ๏ผŒFluxๅฐ†ไธ€ไธชๅบ”็”จๅˆ†ๆˆๅ››ไธช้ƒจๅˆ†ใ€‚ - **View**๏ผš ่ง†ๅ›พๅฑ‚ - **Action**๏ผˆๅŠจไฝœ๏ผ‰๏ผš่ง†ๅ›พๅฑ‚ๅ‘ๅ‡บ็š„ๆถˆๆฏ๏ผŒ็”จๆฅไฟฎๆ”นๆ•ฐๆฎๆจกๅž‹๏ผˆๆฏ”ๅฆ‚mouseClick๏ผ‰ - **Dispatcher**๏ผˆๆดพๅ‘ๅ™จ๏ผ‰๏ผš็”จๆฅๆŽฅๆ”ถActionsใ€ๆ‰ง่กŒๅ›ž่ฐƒๅ‡ฝๆ•ฐ - **Store**๏ผˆๆ•ฐๆฎๅฑ‚๏ผ‰๏ผš็”จๆฅๅญ˜ๆ”พๅบ”็”จ็š„็Šถๆ€๏ผŒไธ€ๆ—ฆๅ‘็”Ÿๅ˜ๅŠจ๏ผŒๅฐฑๆ้†’Views่ฆๆ›ดๆ–ฐ้กต้ข ![](./img/3.png) > Flux ็š„ๆœ€ๅคง็‰น็‚น๏ผŒๅฐฑๆ˜ฏๆ•ฐๆฎ็š„"ๅ•ๅ‘ๆตๅŠจ"ใ€‚ > > > > 1. ็”จๆˆท่ฎฟ้—ฎ View๏ผŒ๏ผˆๅŒๆ—ถๅฐ†Viewไธญ่ง†ๅ›พๆ›ดๆ–ฐ็š„ๅ‡ฝๆ•ฐ่ต‹ๅ€ผ็ป™Store็š„็›‘ๅฌๅ‡ฝๆ•ฐsubscribe๏ผ‰ > 2. View ๅ‘ๅ‡บ็”จๆˆท็š„ Action > 3. Dispatcher ๆ”ถๅˆฐ Action๏ผŒ่ฆๆฑ‚ Store ่ฟ›่กŒ็›ธๅบ”็š„ๆ›ดๆ–ฐ > 4. Store ๆ›ดๆ–ฐๅŽ๏ผŒ๏ผˆ่งฆๅ‘Store็š„subscribeๅ‡ฝๆ•ฐๆฅๆ›ดๆ–ฐView่ง†ๅ›พ๏ผ‰ ### 2ใ€็คบไพ‹ ๆ•ˆๆžœ๏ผšๅˆ›ๅปบList็ป„ไปถๆ˜พ็คบๅˆ—่กจ๏ผŒ็‚นๅ‡ปๆทปๅŠ ๆŒ‰้’ฎๆทปๅŠ ๆ•ฐๆฎ๏ผŒ็‚นๅ‡ปๅˆ ้™คๆŒ‰้’ฎๅˆ ้™คๆœ€ๅŽไธ€ไธชๆ•ฐๆฎใ€‚ #### 2.1ใ€ๅˆ›ๅปบstore๏ผŒไฟๅญ˜ๆ•ฐๆฎๆจกๅž‹ ```jsx export let store = { state: { list: [ { name: 'ๅ•†ๅ“1' }, { name: 'ๅ•†ๅ“2' }, { name: 'ๅ•†ๅ“3' }, { name: 'ๅ•†ๅ“4' }, ] }, } ``` #### 2.2ใ€ๅˆ›ๅปบaction ็‚นๅ‡ปๆŒ‰้’ฎ็š„ๆ—ถๅ€™ๆ—ถๅ€™ๅˆ›ๅปบใ€‚ ๅˆ›ๅปบ็š„ๆ—ถๅ€™ๆทปๅŠ `type`ๅฑžๆ€งๆ˜ฏไธบไบ†ๅˆ†่พจไน‹ๅŽ่ฏฅๅฆ‚ไฝ•ๆ“ไฝœstoreใ€‚ ```jsx // List.js import { store } from './store' import dispatcher from './dispatcher' export class List extends React.Component { constructor() { super(); // ListๅŠ ่ฝฝ็š„ๆ—ถๅ€™๏ผŒ้€š่ฟ‡store.getList()ๅ‡ฝๆ•ฐ่Žทๅ–store็š„ๆ•ฐๆฎ this.state = store.getList(); this.add = this.add.bind(this); this.del = this.del.bind(this); } add() { // ๅˆ›ๅปบaction let action = { type: 'ADD_ITEM', name: 'ๆ–ฐ็š„ๅ•†ๅ“' } } del() { // ๅˆ›ๅปบaction let action = { type: 'DEL_ITEM' } } render() { let domList = this.state.list.map((item, i) => { return ( <li key={i}> {item.name} </li> ); }) return ( <div> <button onClick={this.add}>ๆทปๅŠ </button> <button onClick={this.del}>ๅˆ ้™ค</button> <ul> {domList} </ul> </div> ) } } ``` > store็š„ๆ•ฐๆฎ่Žทๅ–ไนŸไธ่ƒฝ็›ดๆŽฅๆ“ไฝœ๏ผŒ่€Œๆ˜ฏ้œ€่ฆstore่‡ชๅทฑๆไพ›่‡ชๅฎšไน‰ๆ–นๆณ•ๆ‰ๅฏไปฅใ€‚ #### 2.3ใ€ๅˆ›ๅปบdispatcher ```jsx // dispatcher.js import flux from "flux"; import { store } from "./store"; let Dispatcher = flux.Dispatcher; let dispatcher = new Dispatcher(); dispatcher.register(action => { // ๅ‚ๆ•ฐactionๅณๆ˜ฏ่Žทๅ–ๅˆฐaction็š„ๅ€ผ console.log(action); }) export default dispatcher; ``` ไธบไบ†่ƒฝ่Žทๅ–ๅˆฐaction๏ผŒๆ‰€ไปฅๅœจๅˆ›ๅปบactionไน‹ๅŽ๏ผŒ่ฟ˜่ฆๅ‘้€็ป™dispatcher๏ผš ```js import dispatcher from './dispatcher' add() { let action = { type: 'ADD_ITEM', name: 'ๆ–ฐ็š„ๅ•†ๅ“' } dispatcher.dispatch(action); } del() { let action = { type: 'DEL_ITEM' } dispatcher.dispatch(action); } ``` #### 2.4ใ€ๆ›ดๆ–ฐstore dispatcher่Žทๅ–ๅˆฐactionๅŽ้œ€่ฆๆ›ดๆ–ฐstoreใ€‚ไนŸ้œ€่ฆ่ฐƒ็”จstoreๆไพ›็š„่‡ชๅฎšไน‰ๆ–นๆณ•ใ€‚ ```jsx // store.js export let store = { state: { list: [ { name: 'ๅ•†ๅ“1' }, { name: 'ๅ•†ๅ“2' }, { name: 'ๅ•†ๅ“3' }, { name: 'ๅ•†ๅ“4' }, ] }, getList() { return this.state; }, // ่‡ชๅฎšไน‰ๆ“ไฝœstoreๆ–นๆณ• addList(name) { this.state.list.push({ name }); }, delList(name) { this.state.list.pop(); }, } ``` ```jsx // dispatcher.js import flux from "flux"; import { store } from "./store"; let Dispatcher = flux.Dispatcher; let dispatcher = new Dispatcher(); dispatcher.register(action => { // ๆ นๆฎtypeๆฅๆ“ไฝœไธๅŒ็š„storeๆ–นๆณ• switch (action.type) { case 'ADD_ITEM': store.addList(action.name); break; case 'DEL_ITEM': store.delList(); break; default: break; } }) export default dispatcher; ``` #### 2.5ใ€ๆ›ดๆ–ฐview ๆญคๆ—ถstoreๅทฒ็ปๆ›ดๆ–ฐ๏ผŒไฝ†ๆ˜ฏviewๆฒกๆœ‰ๆ›ดๆ–ฐ๏ผŒๅฆ‚ไฝ•ๆ›ดๆ–ฐview๏ผŸ > ๅœจstoreๅฎšไน‰ไธ€ไธชๅ˜้‡bindUpdate๏ผŒ็”จๆฅ่ฐƒ็”จview็š„ๆ›ดๆ–ฐๆ–นๆณ•ใ€‚ๅœจListๅŠ ่ฝฝๆ—ถๅฐฑๆŠŠbindUpdate่ต‹ๅ€ผไธบview็š„ๆ›ดๆ–ฐๆ–นๆณ•๏ผŒๅช่ฆstore็š„ๆ•ฐๆฎไธ€ๆ›ดๆ–ฐ๏ผŒๅฐฑ่ฐƒ็”จ่ฟ™ไธชๆ–นๆณ•ๆฅๆ›ดๆ–ฐ่ง†ๅ›พใ€‚ ```jsx export let store = { state: { list: [ { name: 'ๅ•†ๅ“1' }, { name: 'ๅ•†ๅ“2' }, { name: 'ๅ•†ๅ“3' }, { name: 'ๅ•†ๅ“4' }, ] }, // ๅฎšไน‰ๆ›ดๆ–ฐviewๅ˜้‡ bindUpdate: null, getList() { return this.state; }, addList(name) { // ๆ›ดๆ–ฐstore this.state.list.push({ name }); // ๆ‰ง่กŒๆ›ดๆ–ฐview this.bindUpdate(); }, delList(name) { // ๆ›ดๆ–ฐstore this.state.list.pop(); // ๆ‰ง่กŒๆ›ดๆ–ฐview this.bindUpdate(); }, } ``` ```jsx import { store } from './store' import dispatcher from './dispatcher' export class List extends React.Component { constructor() { super(); this.state = store.getList(); this.add = this.add.bind(this); this.del = this.del.bind(this); } componentDidMount = () => { // ListๅŠ ่ฝฝๅฎŒๆˆๅŽๅฐ†bindUpdate่ต‹ๅ€ผไธบๆ›ดๆ–ฐๆ–นๆณ• store.bindUpdate = this.updateView.bind(this); } add() { let action = { type: 'ADD_ITEM', name: 'ๆ–ฐ็š„ๅ•†ๅ“' } dispatcher.dispatch(action); } del() { let action = { type: 'DEL_ITEM' } dispatcher.dispatch(action); } // ๆ›ดๆ–ฐๆ–นๆณ•๏ผŒ่Žทๅ–store.state็š„ๆœ€ๆ–ฐๆ•ฐๆฎ่ฟ›่กŒๆ›ดๆ–ฐ updateView() { this.setState(store.state) } render() { let domList = this.state.list.map((item, i) => { return ( <li key={i}> {item.name} </li> ); }) return ( <div> <button onClick={this.add}>ๆทปๅŠ </button> <button onClick={this.del}>ๅˆ ้™ค</button> <ul> {domList} </ul> </div> ) } } ``` ไบŽๆ˜ฏไนŽ๏ผŒๆ•ดไธชๅ•ๅ‘ๆตๅŠจๅพช็ŽฏๅฎŒๆˆใ€‚ ##### ไผ˜ๅŒ–viewๆ›ดๆ–ฐ ไน‹ๅ‰view็š„ๆ›ดๆ–ฐๆ˜ฏ้€š่ฟ‡ๅฐ†List็š„ไธ€ไธชๆ›ดๆ–ฐๆ–นๆณ•่ต‹ๅ€ผ็ป™store็š„ไธ€ไธชๅ˜้‡๏ผŒไฝ†ๆ˜ฏๆœ‰ไธช้—ฎ้ข˜ๆ˜ฏ๏ผŒๅฆ‚ๆžœๆœ‰ๅพˆๅคšไธช็ป„ไปถ็š„่ฏ๏ผŒๅฐฑ็”ฑๅพˆๅคšไธชstore๏ผŒๅฐฑ้œ€่ฆๅพˆๅคšไธชๅ˜้‡๏ผŒ้‚ฃๅฐฑๅคช้บป็ƒฆไบ†๏ผŒๅ…ถๅ็งฐๅคด้ƒฝ่ตทๅคงไบ†ใ€‚ ๆ‰€ไปฅ๏ผŒๆˆ‘ไปฌๅฏไปฅ้€š่ฟ‡node่‡ชๅธฆ็š„eventๅฏน่ฑกๆฅๅš่ง‚ๅฏŸ่€…ๆจกๅผใ€‚ ```jsx let EventEmitter = require('events').EventEmitter; let event = new EventEmitter(); export let store = { state: { list: [ { name: 'ๅ•†ๅ“1' }, { name: 'ๅ•†ๅ“2' }, { name: 'ๅ•†ๅ“3' }, { name: 'ๅ•†ๅ“4' }, ] }, getList() { return this.state; }, addList(name) { this.state.list.push({ name }); // ๆฏๆฌกๆ•ฐๆฎๆจกๅž‹ๆœ‰ๅ˜ๆ›ด๏ผŒ่งฆๅ‘updateไบ‹ไปถ event.emit('update'); }, delList(name) { this.state.list.pop(); // ๆฏๆฌกๆ•ฐๆฎๆจกๅž‹ๆœ‰ๅ˜ๆ›ด๏ผŒ่งฆๅ‘updateไบ‹ไปถ event.emit('update'); }, bindUpdate(cb) { // ็›‘ๅฌupdateไบ‹ไปถ event.on('update', cb); }, unBindUpdate(cb) { this.removeListener('update', cb); } } ``` ๅœจList้‡Œ้ขๅŠ ่ฝฝๅฎŒๆˆๅŽ่ฟ›่กŒ็ป‘ๅฎš`bindUpdate`ๅ‡ฝๆ•ฐ๏ผš ๅธ่ฝฝ็š„ๆ—ถๅ€™็ป‘ๅฎš`unBindUpdate`ๅ‡ฝๆ•ฐ๏ผš ```js componentDidMount = () => { store.bindUpdate(this.updateView.bind(this)); } componentWillUnmount() { store.unBindUpdate(this.updateView.bind(this)); } ``` ่ฟ™ๆ—ถๅ€™ไธ็ฎกๆœ‰ๅคšๅฐ‘ไธช็ป„ไปถ๏ผŒ้ƒฝๅฏไปฅไฝฟ็”จbindUpdateๅ’ŒunBindUpdate่ฟ›่กŒ่ง†ๅ›พๆ›ดๆ–ฐใ€‚ ##### ็ปง็ปญไผ˜ๅŒ– ๆˆ‘ไปฌไฝฟ็”จevent็š„ๆ—ถๅ€™๏ผŒnewไบ†ไธ€ไธชๅฏน่ฑก๏ผŒๅฏๆ˜ฏๅฐฑๅช็”จๅˆฐไบ†onๅ’Œemitๆ–นๆณ•๏ผŒๅคชๆตช่ดนๅ†…ๅญ˜ไบ†ใ€‚ ๆˆ‘ไปฌๅ‘็Žฐeventๅฏน่ฑกไธญๅ…ถๅฎžๆฒกๆœ‰onๅ’Œemitๆ–นๆณ•๏ผŒ่ฟ™ไบ›ๆ–นๆณ•้ƒฝๆ˜ฏEventEmitterๅŽŸๅž‹ๅฏน่ฑกไธญ็š„๏ผŒ้‚ฃไนˆๆˆ‘ไปฌ็›ดๆŽฅๆŠŠEventEmitterๅŽŸๅž‹ๅฏน่ฑกๆ‹ฟ่ฟ‡ๆฅๅฐฑๅฅฝไบ†ใ€‚ ```jsx let EventEmitter = require('events').EventEmitter; export let store = { state: { list: [ { name: 'ๅ•†ๅ“1' }, { name: 'ๅ•†ๅ“2' }, { name: 'ๅ•†ๅ“3' }, { name: 'ๅ•†ๅ“4' }, ] }, // ๆŠŠEventEmitter.prototypeๅ…จ้ƒจcopy่ฟ‡ๆฅ๏ผŒๅฐฑไธ้œ€่ฆnewไบ†ใ€‚ ...EventEmitter.prototype, getList() { return this.state; }, addList(name) { this.state.list.push({ name }); // ๆ‰ง่กŒๆ›ดๆ–ฐ // this.bindUpdate(); this.emit('update'); }, delList(name) { this.state.list.pop(); // ๆ‰ง่กŒๆ›ดๆ–ฐ this.emit('update'); }, bindUpdate(cb) { this.on('update', cb); } } ``` ่ฐƒ็”จ็š„ๆ—ถๅ€™๏ผŒ็›ดๆŽฅไฝฟ็”จthis.onๅ’Œthis.emitๅฐฑๅฏไปฅไบ†ใ€‚ ##### ไผ˜ๅŒ–storeๅ’Œviewๆ›ดๆ–ฐ ไน‹ๅ‰store็š„ๆ›ดๆ–ฐๆ–นๅผๆ˜ฏๅœจdispatcherไธญ่ฐƒ็”จstore็š„ๆ›ดๆ–ฐๅ„ไธชๆ›ดๆ–ฐๆ–นๆณ•่ฟ›่กŒๆ›ดๆ–ฐ๏ผŒๅฆ‚ๆžœๆ–นๆณ•ๅพˆๅคš็š„่ฏ๏ผŒๅฐฑ่ฆๅ†™ๅพˆๅคšๆ–นๆณ•ๆฏ”่พƒ้บป็ƒฆใ€‚ๅนถไธ”ๆฏไธชๆ–นๆณ•ไธญ้ƒฝ้œ€่ฆemitๆ›ดๆ–ฐ่ง†ๅ›พใ€‚ ![](./img/4.png) ![](./img/5.png) ๆ‰€ไปฅๆˆ‘ไปฌๅœจstoreไธญๅขžๅŠ ไธ€ไธช็ฑปไผผreact็š„setStateๆ–นๆณ•๏ผŒไธ€ๆฌกๆ€งๆ›ดๆ”นๆ‰€ๆœ‰store็š„stateใ€‚ ![](./img/6.png) ![](./img/7.png) #### 2.6ใ€่ง†ๅ›พๅˆ†ๅฑ‚ ๆˆ‘ไปฌไน‹ๅ‰List็ป„ไปถ่ง†ๅ›พ็š„ๆ˜พ็คบๅ’Œ้€ป่พ‘ๅค„็†ไปฃ็ ๆ˜ฏๅ†™ๅœจไธ€่ตท็š„๏ผŒ่ง†ๅ›พๅˆ†ๅฑ‚ๅฐฑๆ˜ฏๆŠŠไป–ไปฌๅˆ†ๅผ€ใ€‚ ๅˆ†ๅผ€ๅŽๅˆ†ไธบ`ๅฎนๅ™จ็ป„ไปถ`ๅ’Œ`UI็ป„ไปถ` UI็ป„ไปถๅค่ดŸ่ดฃ่ง†ๅ›พๆ˜พ็คบ๏ผ› ๅฎนๅ™จ็ป„ไปถๅŒ…่ฃนUI๏ผŒๅนถ่ดŸ่ดฃ้€ป่พ‘ๅค„็†ใ€‚ ็Žฐๅœจๅฐ†Listๅˆ†ๅฑ‚๏ผš ๅฎนๅ™จ็ป„ไปถไธบ๏ผš`ListController.js` UI็ป„ไปถไธบ๏ผš`List.js` ```js // List.js export class List extends React.Component { constructor() { super(); } render() { let domList = this.props.list.map((item, i) => { return ( <li key={i}> {item.name} </li> ); }) return ( <div> <button onClick={this.props.add}>ๆทปๅŠ </button> <button onClick={this.props.del}>ๅˆ ้™ค</button> <ul> {domList} </ul> </div> ) } } ``` ```jsx //ListController.js import { store } from '../store' import dispatcher from '../dispatcher' import { List } from './List' export class ListController extends React.Component { constructor() { super(); this.state = store.getState(); this.add = this.add.bind(this); this.del = this.del.bind(this); } componentDidMount = () => { store.bindUpdate(this.updateView.bind(this)); } componentWillUnmount() { store.unBindUpdate(this.updateView.bind(this)); } add() { let action = { type: 'ADD_ITEM', name: 'ๆ–ฐ็š„ๅ•†ๅ“' } dispatcher.dispatch(action); } del() { let action = { type: 'DEL_ITEM' } dispatcher.dispatch(action); } updateView() { this.setState(store.state) } render() { // ่ฐƒ็”จList UI็ป„ไปถ return <List list={this.state.list} add={this.add} del={this.del} /> } } ``` ### 3ใ€flux้กน็›ฎๆ€่ทฏ 1ใ€ๅฐ†่ง†ๅ›พ้ƒจๅˆ†็š„้กต้ข็ป„ไปถๆ‹†ๅˆ†ๆˆๅฎนๅ™จ็ป„ไปถๅ’ŒUI็ป„ไปถ ๅฎนๅ™จ็ป„ไปถๅฏ็ปงๆ‰ฟ ๅฐ่ฃ…ๅฅฝ็š„ Controller ไปฅ่‡ชๅŠจๅฎž็Žฐ็ป‘ๅฎšๆ›ดๆ–ฐ่ง†ๅ›พๆ–นๆณ•ๅŠๅธ่ฝฝ็ป„ไปถๆ—ถ่‡ชๅŠจ่งฃ็ป‘๏ผŒ้ฟๅ…ๆ‰€ๆœ‰ๅฎนๅ™จ็ป„ไปถๅ†™็›ธๅŒ็š„ไปฃ็ ใ€‚ ๏ผˆๅ…ถไธญๅทฎๅผ‚้ƒจๅˆ†ๅ„ไธช็ป„ไปถ็š„store้€š่ฟ‡ๆž„้€ ๅ‡ฝๆ•ฐ็š„็ฌฌไบŒไธชๅ‚ๆ•ฐไผ ๅ…ฅใ€‚๏ผ‰ ```jsx export class Controller extends React.Component { constructor(props, store) { super(props); this.store = store; this.state = this.store.getState(); this.store.subscribe(this.updateView.bind(this)); } updateView() { this.setState(this.store.getState()); } componentWillUnmount() { this.store.unBindUpdate(this.updateView.bind(this)); } } ``` > Controller ไน‹ๆ‰€ไปฅ็ปงๆ‰ฟ React.Componentๆ˜ฏๅ› ไธบๅฎนๅ™จ็ป„ไปถ้œ€่ฆ๏ผŒไฝ†ๆ˜ฏๅˆไธ่ƒฝๅŒๆ—ถ็ปงๆ‰ฟControllerๅ’ŒReact.Component๏ผŒๆ‰€ไปฅ้‡‡ๅ–่ฟ™็งๅตŒๅฅ—็ปงๆ‰ฟ็š„ๆ–นๅผใ€‚ UI็ป„ไปถๆ‰€ๆœ‰ๆ•ฐๆฎ(็‚นๅ‡ป็ญ‰ๅ„็งไบ‹ไปถๆ‰€่ฐƒ็”จ็š„ๅ‡ฝๆ•ฐ)ๅ‡ๆฅ่‡ชไบŽprops(็”ฑๅฎนๅ™จ็ป„ไปถไผ ๅ…ฅ) ็ฑปไผผไปฅไธ‹ๆ–นๅผ๏ผš ```jsx render() { return <Home {...this.state} /> } ``` `<Home />` ๅณๆ˜ฏUI็ป„ไปถใ€‚ this.state ๅ“ช้‡Œๆฅๅ‘ข๏ผŸ ๆฅ่‡ชๅฏนๅบ”็š„store๏ผšthis.state = HomeStore.getState(); store็š„stateๆฅ่‡ชๅ“ช้‡Œๅ‘ข๏ผŸ ๆฅ่‡ช้กต้ขๅŠ ่ฝฝๆ—ถajax่ฏทๆฑ‚๏ผŒ่ฏทๆฑ‚ๅˆฐๆ•ฐๆฎๅ†™ๅ…ฅstoreใ€‚ ๆ—ข็„ถ่ฆๆ“ไฝœstore๏ผŒ้‚ฃไนˆๅฐฑ่ฆ้€š่ฟ‡action->dispatcher->store->view็š„้กบๅบๆฅใ€‚ 2ใ€ๅˆ›ๅปบactionๅทฅๅŽ‚ๅ‡ฝๆ•ฐ - ๅฎšไน‰ไธ€ไธชๅˆๅง‹ๅŒ– ็š„actionๅทฅๅŽ‚ๅ‡ฝๆ•ฐ - ่ฏทๆฑ‚้œ€่ฆ็š„ๆ•ฐๆฎ - ๅฐ†ๆ‹ฟๅˆฐ็š„ๆ•ฐๆฎๅฐ่ฃ…ๅˆฐ actionไธญ - ๅฐ†actionๅ‘้€ๅˆฐdispatcher (้€š่ฟ‡.dispatch()ๆ–นๆณ•) 3ใ€ๅœจๆดพๅ‘ๅ™จdispatcherไธญ้…็ฝฎๅฏนๅบ”็š„case ๅนถไธ”ไปŽactionไธญๆ‹ฟๅˆฐๆ•ฐๆฎๅŽ๏ผŒ่ฎพ็ฝฎๅˆฐๅฏนๅบ”storeไธญๅณๅฏ ้€š่ฟ‡ๅ„่‡ช็ป„ไปถ็š„็ฑปไผผ`HomeStore.setState(action);`ๆ–นๅผ่ฟ›่กŒ่ฎพ็ฝฎใ€‚ store็š„stateๆ›ดๆ–ฐไบ†๏ผŒๆณจๆ„้œ€่ฆๅœจๅฎนๅ™จ็ป„ไปถๅŠ ่ฝฝๅฎŒๆˆๅŽ็ป‘ๅฎš่ง†ๅ›พๆ›ดๆ–ฐๆ–นๆณ•๏ผŒ่ง†ๅ›พๆ›ดๆ–ฐๆ–นๆณ•ๅฐฑๆ˜ฏ็ป„ไปถ่Žทๅ–ๆœ€ๆ–ฐstore็š„stateๆ•ฐๆฎใ€‚ 4ใ€ๅœจๅฎนๅ™จ็ป„ไปถ็š„ๅŠ ่ฝฝๅฎŒๆˆ็š„็”Ÿๅ‘ฝๅ‘จๆœŸๅ‡ฝๆ•ฐไธญ๏ผŒ่ฐƒ็”จไธŠ่ฟฐๆญฅ้ชคๅฐ่ฃ…ๅฅฝ็š„actionๅทฅๅŽ‚ๅ‡ฝๆ•ฐ๏ผˆไนŸๅฐฑๆ˜ฏๆ‰“ๅผ€้กต้ข็š„ๆ—ถๅ€™่ฟ›่กŒajax่ฏทๆฑ‚๏ผ‰ 5ใ€่ทฏ็”ฑ้ƒจๅˆ†ๅผ•ๅ…ฅ็š„็ป„ไปถ ๆณจๆ„้œ€่ฆๅˆ‡ๆขๆˆๅฎนๅ™จ็ป„ไปถใ€‚ ## ็ฎ€ๆ˜“flux้กน็›ฎ ้“พๆŽฅ๏ผšhttps://github.com/Daotin/daotin.github.io/issues/132#issue-602918224
Daotin/Web/13-React/05-Fluxๆžถๆž„.md/0
{ "file_path": "Daotin/Web/13-React/05-Fluxๆžถๆž„.md", "repo_id": "Daotin", "token_count": 8268 }
19
## ไธ€ใ€ๆŽฅๅฃ jsไธญ็ฑป็š„ๆŽฅๅฃๅฎšไน‰๏ผš ```typescript interface Human { run(); eat(); } ``` > ๆŽฅๅฃ็š„ๆ–นๆณ•ๆฒกๆœ‰ๆ–นๆณ•ไฝ“ใ€‚ > > ๅฎž็ŽฐๆŽฅๅฃ็š„็ฑป๏ผŒๅฟ…้กปๅฎž็ŽฐๆŽฅๅฃไธญ็š„ๆ‰€ๆœ‰ๆ–นๆณ•ใ€‚ ## ไบŒใ€ไพ่ต–ๆณจๅ…ฅ(ๆœๅŠก) ไพ่ต–ๆณจๅ…ฅๅฐฑๆ˜ฏ่‡ชๅทฑๅˆ›ๅปบไธ€ไธชๆœๅŠก๏ผˆๆœๅŠก็š„ๆœฌ่ดจๅฐฑๆ˜ฏไธ€ไธช็ฑป๏ผ‰๏ผŒ็„ถๅŽๅœจไฝฟ็”จ็ฑป็š„ๆ—ถๅ€™๏ผŒไธ้œ€่ฆ่‡ชๅทฑnew็ฑป็š„ๅฎžไพ‹๏ผŒๅช้œ€่ฆๆŒ‰็…ง็‰นๅฎš็š„ๆ–นๅผๆณจๅ…ฅ๏ผŒ็ฑป็š„ๅฎžไพ‹ๅฐฑไผš่ขซ่‡ชๅŠจๅˆ›ๅปบ๏ผŒ็„ถๅŽ็›ดๆŽฅไฝฟ็”จๅณๅฏใ€‚ ### 1ใ€ๅˆ›ๅปบๆœๅŠก ```js ng g service services/DIYMath // ng g s services/DIYMath ``` ๅˆ›ๅปบ็š„ๆ—ถๅ€™ไผšๆœ‰ไธช่ญฆๅ‘Š`WARNING Service is generated but not provided, it must be provided to be used` ๆœชๅผ•ๅ…ฅๆœๅŠก๏ผŒๅŽ้ขๆณจๆ„ๅผ•ๅ…ฅใ€‚ ### 2ใ€ๅฎž็ŽฐๆœๅŠก้€ป่พ‘ไปฃ็  ```typescript import { Injectable } from '@angular/core'; // ๆœๅŠก่ฃ…้ฅฐๅ™จ // ไฝœ็”จ๏ผšๆญคๆœๅŠกๅฏไปฅๅ†่ฐƒ็”จๅˆซ็š„ๆœๅŠก @Injectable() export class DIYMathService { // ๅฆ‚ๆžœ่ฐƒ็”จๅˆซ็š„ๆœๅŠก constructor(private xxx:newDIYMath) { } // ๅŠ  add(a: number, b: number): number { return a * 1 + b * 1; } // ๅ‡ reduce(a: number, b: number): number { return a * 1 - b * 1; } } ``` ### 3ใ€ๅœจไธปๆจกๅ—ไธญๆณจๅ…ฅๆœๅŠก ```typescript // app.module.ts providers: [DIYMathService], ``` > ๅฆ‚ๆžœๆœชๅœจไธปๆจกๅ—ไธญๆณจๅ…ฅๆœๅŠก็š„่ฏ๏ผŒไผšๆŠฅ`DI Error` ้”™่ฏฏใ€‚ ### 4ใ€ๅœจ็ป„ไปถไธญไฝฟ็”จๆœๅŠก ```typescript // a.component.ts import { DIYMathService } from 'app/services/diymath.service'; export class AComponent implements OnInit { constructor( // ไฝฟ็”จDIYMathServiceๆœๅŠก private dm: DIYMathService ) { } a: number = 0; b: number = 0; alg: string = '+'; result: number = 0; opt() { this.result = this.dm[this.alg](this.a, this.b); } ngOnInit() { } } ``` ```html <!-- a.component.html --> <div> <input type="text" [(ngModel)]="a"> <select (change)="opt()" [(ngModel)]="alg"> <option value="add">+</option> <option value="reduce">-</option> </select> <input type="text" [(ngModel)]="b"> = <span>{{result}}</span> </div> ``` ### 5ใ€Tips ๅฆ‚ๆžœๆญคๆ—ถๆˆ‘ไปฌ็š„้กน็›ฎๆœ‰ๅพˆๅคšๅœฐๆ–นไฝฟ็”จไบ†DIYMathServiceๆœๅŠก๏ผŒไฝ†ๆ˜ฏๆˆ‘ไปฌๅˆๅˆ›ๅปบไบ†ไธ€ไธชๆ–ฐ็š„ๆœๅŠกNewDIYMathService๏ผŒๅฎƒๆฏ”DIYMathService่ฆๅฅฝ๏ผŒๆ‰€ไปฅๆˆ‘ไปฌๅƒๅฐ†้กน็›ฎไธญๆ‰€ๆœ‰็š„DIYMathServiceๆ›ฟๆขๆˆNewDIYMathService๏ผŒๆ€Žไนˆๆ›ฟๆข๏ผŸไธ€ไธชไธชๆ‰‹ๆ”น๏ผŸ ไธ้œ€่ฆ๏ผŒๅช้œ€่ฆๅœจๆณจๅ…ฅไธปๆจกๅ—็š„ๆ—ถๅ€™๏ผŒ**ๆŒ‚็พŠๅคดๅ–็‹—่‚‰**ๅณๅฏ๏ผš ``` ๅฐ† providers: [DIYMathService], ๆ”นไธบ๏ผš providers: [{ provide: DIYMathService, useClass: NewDIYMathService }], ``` > ๅ…ถๅฎž`providers: [DIYMathService]` > > ๅฐฑ็›ธๅฝ“ไบŽ`providers: [{ provide: DIYMathService, useClass: DIYMathService}]` > ๆณจๆ„๏ผšๅฆ‚ๆžœๆŒ‚็พŠๅคดๅ–็‹—่‚‰๏ผŒ้‚ฃไนˆๅœจ็‹—่‚‰็š„ๆœๅŠก้‡Œ้ขไธ่ƒฝๅผ•ๅ…ฅ็พŠๅคดๆœๅŠก๏ผŒๅฆๅˆ™ๆŠฅ้”™๏ผ ไนŸๅฐฑๆ˜ฏไธ‹้ข็š„ๅ†™ๆณ•ๆŠฅ้”™๏ผš ```typescript import { Injectable } from '@angular/core'; import { DIYMathService } from './diymath.service'; @Injectable() // ็‹—่‚‰ export class NewDIYMathService { // ๅผ•ๅ…ฅ็พŠๅคด constructor(public dm: DIYMathService) { } // ... } ``` ![](./img/8.png) ## ไธ‰ใ€httpไปฃ็† ็”ฑไบŽangularๆฒกๆœ‰ไฝฟ็”จwebpack๏ผŒๆ‰€ไปฅhttpไปฃ็†็š„้…็ฝฎๅ’Œไน‹ๅ‰็š„ไธๅŒใ€‚ ๅฆ‚ไฝ•่ฎพ็ฝฎhttpไปฃ็†๏ผŸ 1ใ€ๆ–ฐๅปบhttpไปฃ็†ๆ–‡ไปถ๏ผˆโš  **ๆ–‡ไปถๅญ˜ๆ”พๅœจ้กน็›ฎๆ น็›ฎๅฝ•ไธ‹**๏ผ‰ ```json // proxy.config.json { "/zhuiszhu": { "target": "http://www.projectlog.top:3000" } } ``` 2ใ€ๆทปๅŠ ๅˆฐ้กน็›ฎๅฏๅŠจไธญ ```json // package.json "scripts": { "start": "ng serve --proxy-config proxy.config.json", }, ``` > ๐Ÿ’ก ่ฎฐๅพ—่ฆ้‡ๅฏๆœๅŠกๅ“ฆ๏ผ 3ใ€ๅ‘่ตทhttp่ฏทๆฑ‚ angularๆœ‰ๅ†…็ฝฎ็š„http่ฏทๆฑ‚ๆœๅŠก๏ผŒๅช้œ€่ฆๆณจๅ…ฅๅณๅฏไฝฟ็”จใ€‚ ```js import { Http } from '@angular/http'; export class HomeComponent implements OnInit { // ๆณจๅ…ฅไฝฟ็”จHttpๆœๅŠก constructor(private http: Http) { } ngOnInit() { // ๅ‘่ตทajax่ฏทๆฑ‚ this.http.get('/zhuiszhu/goods/getList').subscribe(res => { // res.json()ๅฏไปฅ่Žทๅ–็š„ๆƒณ่ฆ็š„ๆ•ฐๆฎ console.log(res.json()); }) } } ```
Daotin/Web/14-Angular/04-ๆŽฅๅฃ๏ผŒไพ่ต–ๆณจๅ…ฅ๏ผŒhttpไปฃ็†.md/0
{ "file_path": "Daotin/Web/14-Angular/04-ๆŽฅๅฃ๏ผŒไพ่ต–ๆณจๅ…ฅ๏ผŒhttpไปฃ็†.md", "repo_id": "Daotin", "token_count": 2171 }
20
Manifest-Version: 1.0 Class-Path:
Humsen/web/web-core/src/META-INF/MANIFEST.MF/0
{ "file_path": "Humsen/web/web-core/src/META-INF/MANIFEST.MF", "repo_id": "Humsen", "token_count": 15 }
21
package pers.husen.web.common.constants; /** * ๆ•ฐๆฎๅบ“ๅญ—ๆฎตๅธธ้‡ * * @author ไฝ•ๆ˜Ž่ƒœ * * 2017ๅนด11ๆœˆ8ๆ—ฅ */ public class DbConstans { /** ๆ•ฐๆฎๅบ“ๅญ—ๆฎตๆœ‰ๆ•ˆ็Šถๆ€ */ public static final int FIELD_VALID_FLAG = 0; /** ๆ•ฐๆฎๅบ“ๅญ—ๆฎตๅˆ ้™ค็Šถๆ€ */ public static final int FIELD_DELETED_FLAG = 1; }
Humsen/web/web-core/src/pers/husen/web/common/constants/DbConstans.java/0
{ "file_path": "Humsen/web/web-core/src/pers/husen/web/common/constants/DbConstans.java", "repo_id": "Humsen", "token_count": 159 }
22
/** * ้€š็”จๅŠฉๆ‰‹ * * @author ไฝ•ๆ˜Ž่ƒœ * * 2017ๅนด10ๆœˆ21ๆ—ฅ */ package pers.husen.web.common.helper;
Humsen/web/web-core/src/pers/husen/web/common/helper/package-info.java/0
{ "file_path": "Humsen/web/web-core/src/pers/husen/web/common/helper/package-info.java", "repo_id": "Humsen", "token_count": 54 }
23
package pers.husen.web.dao; /** * @author ไฝ•ๆ˜Ž่ƒœ * * 2017ๅนด9ๆœˆ30ๆ—ฅ */ public interface VisitTotalDao { /** * ๆŸฅ่ฏขๆ‰€ๆœ‰่ฎฟ้—ฎ้‡ * @return */ public int queryVisitTotal(); /** * ๆŸฅ่ฏขๅฝ“ๆ—ฅ่ฎฟ้—ฎ้‡ * @return */ public int queryVisitToday(); /** * ๆ›ดๆ–ฐๅฝ“ๆ—ฅ่ฎฟ้—ฎ้‡ๅ’Œๆ€ป่ฎฟ้—ฎ้‡ * * @param visitDate * @return */ public int updateVisitCount(); }
Humsen/web/web-core/src/pers/husen/web/dao/VisitTotalDao.java/0
{ "file_path": "Humsen/web/web-core/src/pers/husen/web/dao/VisitTotalDao.java", "repo_id": "Humsen", "token_count": 192 }
24
package pers.husen.web.dbutil.mappingdb; /** * @author ไฝ•ๆ˜Ž่ƒœ * @desc ๆ–‡็ซ ๅˆ†็ฑปๆ•ฐๆฎๅบ“ๆ˜ ๅฐ„ * @created 2017ๅนด12ๆœˆ12ๆ—ฅ ไธŠๅˆ10:14:34 */ public class ArticleCategoryMapping { /** * ๆ•ฐๆฎๅบ“ๅ็งฐ */ public static final String DB_NAME = "article_category"; public static final String CATEGORY_ID = "category_id"; public static final String CATEGORY_NAME = "category_name"; public static final String CREATE_DATE = "create_date"; public static final String CATEGORY_DELETE = "category_delete"; }
Humsen/web/web-core/src/pers/husen/web/dbutil/mappingdb/ArticleCategoryMapping.java/0
{ "file_path": "Humsen/web/web-core/src/pers/husen/web/dbutil/mappingdb/ArticleCategoryMapping.java", "repo_id": "Humsen", "token_count": 217 }
25
package pers.husen.web.service; import java.util.ArrayList; import pers.husen.web.bean.vo.MessageAreaVo; import pers.husen.web.dao.MessageAreaDao; import pers.husen.web.dao.impl.MessageAreaDaoImpl; /** * @author ไฝ•ๆ˜Ž่ƒœ * * 2017ๅนด9ๆœˆ25ๆ—ฅ */ public class MessageAreaSvc implements MessageAreaDao{ private static final MessageAreaDaoImpl messageAreaDaoImpl = new MessageAreaDaoImpl(); @Override public ArrayList<MessageAreaVo> queryAllMessageArea(int messageId) { return messageAreaDaoImpl.queryAllMessageArea(messageId); } @Override public int insertMessageNew(MessageAreaVo mVo) { return messageAreaDaoImpl.insertMessageNew(mVo); } }
Humsen/web/web-core/src/pers/husen/web/service/MessageAreaSvc.java/0
{ "file_path": "Humsen/web/web-core/src/pers/husen/web/service/MessageAreaSvc.java", "repo_id": "Humsen", "token_count": 231 }
26
package pers.husen.web.servlet.image; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import pers.husen.web.common.handler.ImageDownloadHandler; /** * ๅ›พ็‰‡ไธ‹่ฝฝ * * @author ไฝ•ๆ˜Ž่ƒœ * * 2017ๅนด10ๆœˆ20ๆ—ฅ */ @WebServlet(urlPatterns= {"/imageDownload.hms", "/imageDownload"}) public class ImageDownloadSvt extends HttpServlet { private static final long serialVersionUID = 1L; public ImageDownloadSvt() { super(); } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ImageDownloadHandler iHandler = new ImageDownloadHandler(); iHandler.imageDownloadHandler(request, response); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }
Humsen/web/web-core/src/pers/husen/web/servlet/image/ImageDownloadSvt.java/0
{ "file_path": "Humsen/web/web-core/src/pers/husen/web/servlet/image/ImageDownloadSvt.java", "repo_id": "Humsen", "token_count": 357 }
27
# web ไธชไบบ็ฝ‘็ซ™้กน็›ฎ๏ผŒๅŒ…ๆ‹ฌๅšๅฎขใ€ไปฃ็ ๅบ“ใ€ๆ–‡ไปถไธ‹่ฝฝใ€็•™่จ€ใ€็™ปๅฝ•ๆณจๅ†Œ็ญ‰ๅŠŸ่ƒฝ ็ฝ‘ๅ€๏ผšwww.hemingsheng.cn ------------ ## ไธป่ฆๆ–‡ไปถ็ป“ๆž„ๅฆ‚ไธ‹ - `WebContent` -> ๅ‰็ซฏๆบๆ–‡ไปถ ๏ผˆๅ‰็ซฏไธ‰ๆ–นๆ’ไปถๅœจ`/WebContent/plugins`ไธ‹๏ผ‰ - `config` -> ้…็ฝฎๆ–‡ไปถ - `docs` -> ่ฏดๆ˜Žๆ–‡ๆกฃ - `libs` -> ๅŽ็ซฏjarๅŒ… - `src` -> ๅŽ็ซฏๆบๆ–‡ไปถ ------------ ### webๅทฅ็จ‹็›ฎๅฝ•็ป“ๆž„ๅฆ‚ไธ‹๏ผš web: โ”‚ .classpath โ”‚ .gitattributes โ”‚ .gitignore โ”‚ .project โ”‚ README.md โ”‚ โ”œโ”€config โ”‚ db_connect_info.properties โ”‚ log4j2.xml โ”‚ โ”œโ”€docs โ”‚ webๅŽ็ซฏๅ‘ฝๅ่ง„่Œƒ.txt โ”‚ web้กน็›ฎๅ‰็ซฏๅ‘ฝๅ่ง„่Œƒ.txt โ”‚ ็ฝ‘็ซ™logoๅ›พ็‰‡.png โ”‚ โ”œโ”€libs โ”‚ โ”œโ”€file โ”‚ โ”‚ commons-fileupload-1.3.3.jar โ”‚ โ”‚ commons-io-2.5.jar โ”‚ โ”‚ โ”‚ โ”œโ”€javamail โ”‚ โ”‚ javax.mail.jar โ”‚ โ”‚ โ”‚ โ”œโ”€json โ”‚ โ”‚ commons-beanutils-1.7.0.jar โ”‚ โ”‚ commons-collections-3.1.jar โ”‚ โ”‚ commons-lang-2.5.jar โ”‚ โ”‚ commons-logging.jar โ”‚ โ”‚ ezmorph-1.0.3.jar โ”‚ โ”‚ json-lib-2.4-jdk15.jar โ”‚ โ”‚ โ”‚ โ”œโ”€log4j โ”‚ โ”‚ log4j-api-2.8.2.jar โ”‚ โ”‚ log4j-core-2.8.2.jar โ”‚ โ”‚ โ”‚ โ”œโ”€psql โ”‚ โ”‚ postgresql-42.1.4.jar โ”‚ โ”‚ โ”‚ โ””โ”€servlet โ”‚ servlet-api.jar โ”‚ โ”œโ”€src โ”‚ โ”‚ rebel.xml โ”‚ โ”‚ โ”‚ โ””โ”€pers โ”‚ โ””โ”€husen โ”‚ โ””โ”€web โ”‚ โ”‚ package-info.java โ”‚ โ”‚ โ”‚ โ”œโ”€bean โ”‚ โ”‚ โ”‚ package-info.java โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€po โ”‚ โ”‚ โ”‚ AccessAtatisticsPo.java โ”‚ โ”‚ โ”‚ ImageUploadPo.java โ”‚ โ”‚ โ”‚ package-info.java โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€vo โ”‚ โ”‚ BlogArticleVo.java โ”‚ โ”‚ CodeLibraryVo.java โ”‚ โ”‚ FileDownloadVo.java โ”‚ โ”‚ ImageUploadVo.java โ”‚ โ”‚ MessageAreaVo.java โ”‚ โ”‚ package-info.java โ”‚ โ”‚ ReleaseFeatureVo.java โ”‚ โ”‚ UserInfoVo.java โ”‚ โ”‚ VisitTotalVo.java โ”‚ โ”‚ โ”‚ โ”œโ”€common โ”‚ โ”‚ โ”‚ package-info.java โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€constants โ”‚ โ”‚ โ”‚ BootstrapConstans.java โ”‚ โ”‚ โ”‚ CommonConstants.java โ”‚ โ”‚ โ”‚ package-info.java โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€handler โ”‚ โ”‚ โ”‚ FileDownloadHandler.java โ”‚ โ”‚ โ”‚ FileUploadHandler.java โ”‚ โ”‚ โ”‚ ImageDownloadHandler.java โ”‚ โ”‚ โ”‚ ImageUploadHandler.java โ”‚ โ”‚ โ”‚ package-info.java โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€helper โ”‚ โ”‚ โ”‚ DateFormatHelper.java โ”‚ โ”‚ โ”‚ package-info.java โ”‚ โ”‚ โ”‚ RandomCodeHelper.java โ”‚ โ”‚ โ”‚ SendEmailHelper.java โ”‚ โ”‚ โ”‚ StackTrace2Str.java โ”‚ โ”‚ โ”‚ TypeConvertHelper.java โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€template โ”‚ โ”‚ โ””โ”€html โ”‚ โ”‚ BlogTemplate.java โ”‚ โ”‚ CodeTemplate.java โ”‚ โ”‚ GenericTemplate.java โ”‚ โ”‚ โ”‚ โ”œโ”€config โ”‚ โ”‚ DeployPathConfig.java โ”‚ โ”‚ Log4j2Config.java โ”‚ โ”‚ package-info.java โ”‚ โ”‚ โ”‚ โ”œโ”€dao โ”‚ โ”‚ โ”‚ BlogArticleDao.java โ”‚ โ”‚ โ”‚ CodeLibraryDao.java โ”‚ โ”‚ โ”‚ FileDownloadDao.java โ”‚ โ”‚ โ”‚ ImageUploadDao.java โ”‚ โ”‚ โ”‚ MessageAreaDao.java โ”‚ โ”‚ โ”‚ ReleaseFeatureDao.java โ”‚ โ”‚ โ”‚ UserInfoDao.java โ”‚ โ”‚ โ”‚ VisitTotalDao.java โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€impl โ”‚ โ”‚ BlogArticleDaoImpl.java โ”‚ โ”‚ CodeLibraryDaoImpl.java โ”‚ โ”‚ FileDownloadDaoImpl.java โ”‚ โ”‚ ImageUploadDaoImpl.java โ”‚ โ”‚ MessageAreaDaoImpl.java โ”‚ โ”‚ ReleaseFeatureDaoImpl.java โ”‚ โ”‚ UserInfoDaoImpl.java โ”‚ โ”‚ VisitTotalDaoImpl.java โ”‚ โ”‚ โ”‚ โ”œโ”€dbutil โ”‚ โ”‚ โ”‚ DbDeleteUtils.java โ”‚ โ”‚ โ”‚ DbInsertUtils.java โ”‚ โ”‚ โ”‚ DbQueryUtils.java โ”‚ โ”‚ โ”‚ DbUpdateUtils.java โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€assist โ”‚ โ”‚ โ”‚ AssistUtils.java โ”‚ โ”‚ โ”‚ DbConnectUtils.java โ”‚ โ”‚ โ”‚ package-info.java โ”‚ โ”‚ โ”‚ SetPsParamUtils.java โ”‚ โ”‚ โ”‚ TypeTransformUtils.java โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€mappingdb โ”‚ โ”‚ BlogDetailsMapping.java โ”‚ โ”‚ CodeLibraryMapping.java โ”‚ โ”‚ FileDownloadMapping.java โ”‚ โ”‚ ImageUploadMapping.java โ”‚ โ”‚ MessageAreaMapping.java โ”‚ โ”‚ package-info.java โ”‚ โ”‚ ReleaseFeatureMapping.java โ”‚ โ”‚ UserInfoMapping.java โ”‚ โ”‚ VisitTotalMapping.java โ”‚ โ”‚ โ”‚ โ”œโ”€listener โ”‚ โ”‚ OnlineCountListener.java โ”‚ โ”‚ package-info.java โ”‚ โ”‚ WebInitConfigListener.java โ”‚ โ”‚ โ”‚ โ”œโ”€service โ”‚ โ”‚ BlogArticleSvc.java โ”‚ โ”‚ CodeLibrarySvc.java โ”‚ โ”‚ FileDownloadSvc.java โ”‚ โ”‚ ImageUploadSvc.java โ”‚ โ”‚ MessageAreaSvc.java โ”‚ โ”‚ ReleaseFeatureSvc.java โ”‚ โ”‚ UserInfoSvc.java โ”‚ โ”‚ VisitTotalSvc.java โ”‚ โ”‚ โ”‚ โ””โ”€servlet โ”‚ โ”‚ package-info.java โ”‚ โ”‚ โ”‚ โ”œโ”€blog โ”‚ โ”‚ BlogArticlePerPageServlet.java โ”‚ โ”‚ BlogArticleServlet.java โ”‚ โ”‚ BlogPerByIdServlet.java โ”‚ โ”‚ BlogTotalCountServlet.java โ”‚ โ”‚ NewBlogUploadServlet.java โ”‚ โ”‚ โ”‚ โ”œโ”€codelib โ”‚ โ”‚ CodeLibPerPageServlet.java โ”‚ โ”‚ CodeLibraryServlet.java โ”‚ โ”‚ CodeLibTotalCountServlet.java โ”‚ โ”‚ CodePerByIdServlet.java โ”‚ โ”‚ NewCodeUploadServlet.java โ”‚ โ”‚ โ”‚ โ”œโ”€common โ”‚ โ”‚ AccessAtatisticsServlet.java โ”‚ โ”‚ โ”‚ โ”œโ”€contact โ”‚ โ”‚ SendEmailServlet.java โ”‚ โ”‚ โ”‚ โ”œโ”€download โ”‚ โ”‚ FileDownloadServlet.java โ”‚ โ”‚ FileDownPerPageServlet.java โ”‚ โ”‚ FileDownTotalCountServlet.java โ”‚ โ”‚ FileUploadServlet.java โ”‚ โ”‚ โ”‚ โ”œโ”€image โ”‚ โ”‚ ImageDownloadServlet.java โ”‚ โ”‚ ImageUploadServlet.java โ”‚ โ”‚ package-info.java โ”‚ โ”‚ โ”‚ โ”œโ”€message โ”‚ โ”‚ MessageGetServlet.java โ”‚ โ”‚ MessageUploadServlet.java โ”‚ โ”‚ โ”‚ โ”œโ”€releasefea โ”‚ โ”‚ LatestReleaseFeatureServlet.java โ”‚ โ”‚ NewReleaseFeatureServlet.java โ”‚ โ”‚ โ”‚ โ””โ”€userinfo โ”‚ UserInfoModifyServlet.java โ”‚ UserInfoQueryServlet.java โ”‚ UserInfoRegisterServlet.java โ”‚ UserLoginValidateServlet.java โ”‚ โ””โ”€WebContent โ”‚ index.jsp โ”‚ โ”œโ”€css โ”‚ โ”œโ”€article โ”‚ โ”‚ article.css โ”‚ โ”‚ โ”‚ โ”œโ”€contact โ”‚ โ”‚ contact.css โ”‚ โ”‚ โ”‚ โ”œโ”€download โ”‚ โ”‚ download.css โ”‚ โ”‚ โ”‚ โ”œโ”€error โ”‚ โ”‚ error.css โ”‚ โ”‚ โ”‚ โ”œโ”€index โ”‚ โ”‚ article-profile.css โ”‚ โ”‚ index.css โ”‚ โ”‚ version-feature.css โ”‚ โ”‚ โ”‚ โ”œโ”€login โ”‚ โ”‚ email-check.css โ”‚ โ”‚ login.css โ”‚ โ”‚ retrive-pwd.css โ”‚ โ”‚ โ”‚ โ”œโ”€message โ”‚ โ”‚ message.css โ”‚ โ”‚ pager.css โ”‚ โ”‚ โ”‚ โ”œโ”€navigation โ”‚ โ”‚ left-menu-bar.css โ”‚ โ”‚ rightbar.css โ”‚ โ”‚ topbar.css โ”‚ โ”‚ โ”‚ โ”œโ”€personal_center โ”‚ โ”‚ modify-email.css โ”‚ โ”‚ modify-pwd.css โ”‚ โ”‚ modify-userinfo.css โ”‚ โ”‚ mycenter.css โ”‚ โ”‚ โ”‚ โ””โ”€upload โ”‚ editor-article.css โ”‚ โ”œโ”€error โ”‚ error.jsp โ”‚ โ”œโ”€images โ”‚ โ”‚ favicon.ico โ”‚ โ”‚ mainbg.png โ”‚ โ”‚ โ”‚ โ”œโ”€background โ”‚ โ”‚ bg-1.jpg โ”‚ โ”‚ bg-2.jpg โ”‚ โ”‚ bg-3.jpg โ”‚ โ”‚ bg-4.jpg โ”‚ โ”‚ โ”‚ โ””โ”€message โ”‚ head-0.jpg โ”‚ head-1.jpg โ”‚ head-2.jpg โ”‚ head-3.jpg โ”‚ head-4.jpg โ”‚ head-5.jpg โ”‚ head-6.jpg โ”‚ head-7.jpg โ”‚ head-8.jpg โ”‚ โ”œโ”€js โ”‚ โ”‚ customize-sdk.js โ”‚ โ”‚ is-pc-or-mobile.js โ”‚ โ”‚ pagination.js โ”‚ โ”‚ โ”‚ โ”œโ”€article โ”‚ โ”‚ article-markdown.js โ”‚ โ”‚ blog.js โ”‚ โ”‚ code-library.js โ”‚ โ”‚ โ”‚ โ”œโ”€contact โ”‚ โ”‚ contact.js โ”‚ โ”‚ โ”‚ โ”œโ”€download โ”‚ โ”‚ download.js โ”‚ โ”‚ โ”‚ โ”œโ”€editor โ”‚ โ”‚ editor.js โ”‚ โ”‚ โ”‚ โ”œโ”€index โ”‚ โ”‚ latestblog.js โ”‚ โ”‚ latestcode.js โ”‚ โ”‚ version-feature.js โ”‚ โ”‚ โ”‚ โ”œโ”€login โ”‚ โ”‚ formvalidator.js โ”‚ โ”‚ โ”‚ โ”œโ”€message โ”‚ โ”‚ message.js โ”‚ โ”‚ pager.js โ”‚ โ”‚ โ”‚ โ”œโ”€navigation โ”‚ โ”‚ left-menu-bar.js โ”‚ โ”‚ topbar.js โ”‚ โ”‚ โ”‚ โ””โ”€personal_center โ”‚ modify-email.js โ”‚ modify-pwd.js โ”‚ modify-userinfo.js โ”‚ personal-center.js โ”‚ โ”œโ”€login โ”‚ email_check.html โ”‚ login.jsp โ”‚ retrive_pwd.html โ”‚ โ”œโ”€META-INF โ”‚ MANIFEST.MF โ”‚ โ”œโ”€module โ”‚ blog.jsp โ”‚ code_library.jsp โ”‚ contact.jsp โ”‚ download.jsp โ”‚ message.jsp โ”‚ โ”œโ”€navigation โ”‚ rightbar.jsp โ”‚ topbar.jsp โ”‚ โ”œโ”€personal_center โ”‚ modify_email.html โ”‚ modify_email1.html โ”‚ modify_pwd.html โ”‚ modify_userinfo.html โ”‚ mycenter.jsp โ”‚ โ”œโ”€plugins โ”‚ โ”‚ plugins.jsp โ”‚ โ”‚ โ”‚ โ”œโ”€bootstrap โ”‚ โ”‚ โ”œโ”€css โ”‚ โ”‚ โ”‚ bootstrap.css โ”‚ โ”‚ โ”‚ bootstrap.css.map โ”‚ โ”‚ โ”‚ bootstrap.min.css โ”‚ โ”‚ โ”‚ bootstrap.min.css.map โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€fonts โ”‚ โ”‚ โ”‚ glyphicons-halflings-regular.eot โ”‚ โ”‚ โ”‚ glyphicons-halflings-regular.svg โ”‚ โ”‚ โ”‚ glyphicons-halflings-regular.ttf โ”‚ โ”‚ โ”‚ glyphicons-halflings-regular.woff โ”‚ โ”‚ โ”‚ glyphicons-halflings-regular.woff2 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€js โ”‚ โ”‚ bootstrap.js โ”‚ โ”‚ bootstrap.min.js โ”‚ โ”‚ โ”‚ โ”œโ”€editormd โ”‚ โ”œโ”€jquery โ”‚ โ”‚ โ””โ”€js โ”‚ โ”‚ jquery-3.2.1.min.js โ”‚ โ”‚ jquery.cookie.js โ”‚ โ”‚ jquery.easing.1.3.js โ”‚ โ”‚ jquery.flexslider-min.js โ”‚ โ”‚ jquery.form.min.js โ”‚ โ”‚ jquery.waypoints.min.js โ”‚ โ”‚ โ”‚ โ”œโ”€jqueryconfirm โ”‚ โ”‚ โ”œโ”€css โ”‚ โ”‚ โ”‚ jquery-confirm.min.css โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€js โ”‚ โ”‚ jquery-confirm.min.js โ”‚ โ”‚ โ”‚ โ”œโ”€json โ”‚ โ”‚ โ””โ”€js โ”‚ โ”‚ json2.js โ”‚ โ”‚ โ”‚ โ”œโ”€template โ”‚ โ”‚ โ”œโ”€css โ”‚ โ”‚ โ”‚ animate.css โ”‚ โ”‚ โ”‚ flexslider.css โ”‚ โ”‚ โ”‚ icomoon.css โ”‚ โ”‚ โ”‚ style.css โ”‚ โ”‚ โ”‚ style.css.map โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€js โ”‚ โ”‚ main.js โ”‚ โ”‚ modernizr-2.6.2.min.js โ”‚ โ”‚ โ”‚ โ””โ”€validator โ”‚ โ”œโ”€css โ”‚ โ”‚ bootstrapValidator.css โ”‚ โ”‚ bootstrapValidator.min.css โ”‚ โ”‚ โ”‚ โ””โ”€js โ”‚ โ”‚ bootstrapValidator.js โ”‚ โ”‚ bootstrapValidator.min.js โ”‚ โ”‚ โ”‚ โ””โ”€language โ”‚ ar_MA.js โ”‚ be_FR.js โ”‚ be_NL.js โ”‚ bg_BG.js โ”‚ cs_CZ.js โ”‚ da_DK.js โ”‚ de_DE.js โ”‚ en_US.js โ”‚ es_CL.js โ”‚ es_ES.js โ”‚ fa_IR.js โ”‚ fr_FR.js โ”‚ gr_EL.js โ”‚ he_IL.js โ”‚ hu_HU.js โ”‚ id_ID.js โ”‚ it_IT.js โ”‚ ja_JP.js โ”‚ nl_NL.js โ”‚ no_NO.js โ”‚ pl_PL.js โ”‚ pt_BR.js โ”‚ pt_PT.js โ”‚ ro_RO.js โ”‚ ru_RU.js โ”‚ sq_AL.js โ”‚ sr_RS.js โ”‚ sv_SE.js โ”‚ th_TH.js โ”‚ tr_TR.js โ”‚ ua_UA.js โ”‚ vi_VN.js โ”‚ zh_CN.js โ”‚ zh_TW.js โ”‚ โ”œโ”€upload โ”‚ editor_article.jsp โ”‚ upload_file.jsp โ”‚ โ””โ”€WEB-INF โ”‚ web.xml โ”‚ โ””โ”€lib
Humsen/web/web-mobile/README.md/0
{ "file_path": "Humsen/web/web-mobile/README.md", "repo_id": "Humsen", "token_count": 10856 }
28
@charset "UTF-8"; .topbar-nav { min-height: 30px; width: 100%; margin-bottom: 0; } .topbar-nav label { color: #6e83ab; } .navbar-brand-a { padding: 5px 15px 1px; height: 30px; } .access-today { margin-left: 5% !important; } .online-current { margin-top: 4px; margin-left: 20px; } .topbar-btn-login { padding: 2px 2px !important; font-size: 13px; border: 1px solid #f0ad4e; margin-left: 2%; display: none; } .topbar-btn-pers { padding: 2px 2px !important; font-size: 13px; border: 1px solid #5bc0de; margin-left: 2%; display: none; } .topbar-btn-right { padding: 2px 2px !important; font-size: 13px; border: 1px solid #5bc0de; display: none; margin-left: 6px; } .choose-theme { margin: 10px; } .web-pc-blank { float: left; margin-left: 20px; } .header-nav { float: left; margin-left: 6%; } .choose-theme button { float: left; } .top-bar-div{ margin: 18px 0px 5px 10px; }
Humsen/web/web-mobile/WebContent/css/navigation/topbar.css/0
{ "file_path": "Humsen/web/web-mobile/WebContent/css/navigation/topbar.css", "repo_id": "Humsen", "token_count": 426 }
29
/** * jQuery MD5 hash algorithm function * * <code> * Calculate the md5 hash of a String * String $.md5 ( String str ) * </code> * * Calculates the MD5 hash of str using the ยป RSA Data Security, Inc. MD5 * Message-Digest Algorithm, and returns that hash. MD5 (Message-Digest * algorithm 5) is a widely-used cryptographic hash function with a 128-bit hash * value. MD5 has been employed in a wide variety of security applications, and * is also commonly used to check the integrity of data. The generated hash is * also non-reversable. Data cannot be retrieved from the message digest, the * digest uniquely identifies the data. MD5 was developed by Professor Ronald L. * Rivest in 1994. Its 128 bit (16 byte) message digest makes it a faster * implementation than SHA-1. This script is used to process a variable length * message into a fixed-length output of 128 bits using the MD5 algorithm. It is * fully compatible with UTF-8 encoding. It is very useful when u want to * transfer encrypted passwords over the internet. If you plan using UTF-8 * encoding in your project don't forget to set the page encoding to UTF-8 * (Content-Type meta tag). This function orginally get from the WebToolkit and * rewrite for using as the jQuery plugin. * * Example Code <code> * $.md5("I'm Persian."); * </code> Result <code> * "b8c901d0f02223f9761016cfff9d68df" * </code> * * @alias Muhammad Hussein Fattahizadeh < muhammad [AT] semnanweb [DOT] com > * @link http://www.semnanweb.com/jquery-plugin/md5.html * @see http://www.webtoolkit.info/ * @license http://www.gnu.org/licenses/gpl.html [GNU General Public License] * @param {jQuery} * {md5:function(string)) * @return string */ (function($) { var rotateLeft = function(lValue, iShiftBits) { return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits)); } var addUnsigned = function(lX, lY) { var lX4, lY4, lX8, lY8, lResult; lX8 = (lX & 0x80000000); lY8 = (lY & 0x80000000); lX4 = (lX & 0x40000000); lY4 = (lY & 0x40000000); lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF); if (lX4 & lY4) return (lResult ^ 0x80000000 ^ lX8 ^ lY8); if (lX4 | lY4) { if (lResult & 0x40000000) return (lResult ^ 0xC0000000 ^ lX8 ^ lY8); else return (lResult ^ 0x40000000 ^ lX8 ^ lY8); } else { return (lResult ^ lX8 ^ lY8); } } var F = function(x, y, z) { return (x & y) | ((~x) & z); } var G = function(x, y, z) { return (x & z) | (y & (~z)); } var H = function(x, y, z) { return (x ^ y ^ z); } var I = function(x, y, z) { return (y ^ (x | (~z))); } var FF = function(a, b, c, d, x, s, ac) { a = addUnsigned(a, addUnsigned(addUnsigned(F(b, c, d), x), ac)); return addUnsigned(rotateLeft(a, s), b); }; var GG = function(a, b, c, d, x, s, ac) { a = addUnsigned(a, addUnsigned(addUnsigned(G(b, c, d), x), ac)); return addUnsigned(rotateLeft(a, s), b); }; var HH = function(a, b, c, d, x, s, ac) { a = addUnsigned(a, addUnsigned(addUnsigned(H(b, c, d), x), ac)); return addUnsigned(rotateLeft(a, s), b); }; var II = function(a, b, c, d, x, s, ac) { a = addUnsigned(a, addUnsigned(addUnsigned(I(b, c, d), x), ac)); return addUnsigned(rotateLeft(a, s), b); }; var convertToWordArray = function(string) { var lWordCount; var lMessageLength = string.length; var lNumberOfWordsTempOne = lMessageLength + 8; var lNumberOfWordsTempTwo = (lNumberOfWordsTempOne - (lNumberOfWordsTempOne % 64)) / 64; var lNumberOfWords = (lNumberOfWordsTempTwo + 1) * 16; var lWordArray = Array(lNumberOfWords - 1); var lBytePosition = 0; var lByteCount = 0; while (lByteCount < lMessageLength) { lWordCount = (lByteCount - (lByteCount % 4)) / 4; lBytePosition = (lByteCount % 4) * 8; lWordArray[lWordCount] = (lWordArray[lWordCount] | (string .charCodeAt(lByteCount) << lBytePosition)); lByteCount++; } lWordCount = (lByteCount - (lByteCount % 4)) / 4; lBytePosition = (lByteCount % 4) * 8; lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition); lWordArray[lNumberOfWords - 2] = lMessageLength << 3; lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29; return lWordArray; }; var wordToHex = function(lValue) { var WordToHexValue = "", WordToHexValueTemp = "", lByte, lCount; for (lCount = 0; lCount <= 3; lCount++) { lByte = (lValue >>> (lCount * 8)) & 255; WordToHexValueTemp = "0" + lByte.toString(16); WordToHexValue = WordToHexValue + WordToHexValueTemp.substr(WordToHexValueTemp.length - 2, 2); } return WordToHexValue; }; var uTF8Encode = function(string) { string = string.replace(/\x0d\x0a/g, "\x0a"); var output = ""; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); if (c < 128) { output += String.fromCharCode(c); } else if ((c > 127) && (c < 2048)) { output += String.fromCharCode((c >> 6) | 192); output += String.fromCharCode((c & 63) | 128); } else { output += String.fromCharCode((c >> 12) | 224); output += String.fromCharCode(((c >> 6) & 63) | 128); output += String.fromCharCode((c & 63) | 128); } } return output; }; $.extend({ md5 : function(string) { var x = Array(); var k, AA, BB, CC, DD, a, b, c, d; var S11 = 7, S12 = 12, S13 = 17, S14 = 22; var S21 = 5, S22 = 9, S23 = 14, S24 = 20; var S31 = 4, S32 = 11, S33 = 16, S34 = 23; var S41 = 6, S42 = 10, S43 = 15, S44 = 21; string = uTF8Encode(string); x = convertToWordArray(string); a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476; for (k = 0; k < x.length; k += 16) { AA = a; BB = b; CC = c; DD = d; a = FF(a, b, c, d, x[k + 0], S11, 0xD76AA478); d = FF(d, a, b, c, x[k + 1], S12, 0xE8C7B756); c = FF(c, d, a, b, x[k + 2], S13, 0x242070DB); b = FF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE); a = FF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF); d = FF(d, a, b, c, x[k + 5], S12, 0x4787C62A); c = FF(c, d, a, b, x[k + 6], S13, 0xA8304613); b = FF(b, c, d, a, x[k + 7], S14, 0xFD469501); a = FF(a, b, c, d, x[k + 8], S11, 0x698098D8); d = FF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF); c = FF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1); b = FF(b, c, d, a, x[k + 11], S14, 0x895CD7BE); a = FF(a, b, c, d, x[k + 12], S11, 0x6B901122); d = FF(d, a, b, c, x[k + 13], S12, 0xFD987193); c = FF(c, d, a, b, x[k + 14], S13, 0xA679438E); b = FF(b, c, d, a, x[k + 15], S14, 0x49B40821); a = GG(a, b, c, d, x[k + 1], S21, 0xF61E2562); d = GG(d, a, b, c, x[k + 6], S22, 0xC040B340); c = GG(c, d, a, b, x[k + 11], S23, 0x265E5A51); b = GG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA); a = GG(a, b, c, d, x[k + 5], S21, 0xD62F105D); d = GG(d, a, b, c, x[k + 10], S22, 0x2441453); c = GG(c, d, a, b, x[k + 15], S23, 0xD8A1E681); b = GG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8); a = GG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6); d = GG(d, a, b, c, x[k + 14], S22, 0xC33707D6); c = GG(c, d, a, b, x[k + 3], S23, 0xF4D50D87); b = GG(b, c, d, a, x[k + 8], S24, 0x455A14ED); a = GG(a, b, c, d, x[k + 13], S21, 0xA9E3E905); d = GG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8); c = GG(c, d, a, b, x[k + 7], S23, 0x676F02D9); b = GG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A); a = HH(a, b, c, d, x[k + 5], S31, 0xFFFA3942); d = HH(d, a, b, c, x[k + 8], S32, 0x8771F681); c = HH(c, d, a, b, x[k + 11], S33, 0x6D9D6122); b = HH(b, c, d, a, x[k + 14], S34, 0xFDE5380C); a = HH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44); d = HH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9); c = HH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60); b = HH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70); a = HH(a, b, c, d, x[k + 13], S31, 0x289B7EC6); d = HH(d, a, b, c, x[k + 0], S32, 0xEAA127FA); c = HH(c, d, a, b, x[k + 3], S33, 0xD4EF3085); b = HH(b, c, d, a, x[k + 6], S34, 0x4881D05); a = HH(a, b, c, d, x[k + 9], S31, 0xD9D4D039); d = HH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5); c = HH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8); b = HH(b, c, d, a, x[k + 2], S34, 0xC4AC5665); a = II(a, b, c, d, x[k + 0], S41, 0xF4292244); d = II(d, a, b, c, x[k + 7], S42, 0x432AFF97); c = II(c, d, a, b, x[k + 14], S43, 0xAB9423A7); b = II(b, c, d, a, x[k + 5], S44, 0xFC93A039); a = II(a, b, c, d, x[k + 12], S41, 0x655B59C3); d = II(d, a, b, c, x[k + 3], S42, 0x8F0CCC92); c = II(c, d, a, b, x[k + 10], S43, 0xFFEFF47D); b = II(b, c, d, a, x[k + 1], S44, 0x85845DD1); a = II(a, b, c, d, x[k + 8], S41, 0x6FA87E4F); d = II(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0); c = II(c, d, a, b, x[k + 6], S43, 0xA3014314); b = II(b, c, d, a, x[k + 13], S44, 0x4E0811A1); a = II(a, b, c, d, x[k + 4], S41, 0xF7537E82); d = II(d, a, b, c, x[k + 11], S42, 0xBD3AF235); c = II(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB); b = II(b, c, d, a, x[k + 9], S44, 0xEB86D391); a = addUnsigned(a, AA); b = addUnsigned(b, BB); c = addUnsigned(c, CC); d = addUnsigned(d, DD); } var tempValue = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d); return tempValue.toLowerCase(); } }); })(jQuery);
Humsen/web/web-mobile/WebContent/js/customize-jquery.md5.js/0
{ "file_path": "Humsen/web/web-mobile/WebContent/js/customize-jquery.md5.js", "repo_id": "Humsen", "token_count": 4688 }
30
/** * ็ผ–่พ‘็‰ˆๆœฌ็‰นๆ€ง * * @author ไฝ•ๆ˜Ž่ƒœ * * 2017ๅนด11ๆœˆ10ๆ—ฅ */ // ๅฝ“ๅ‰ๆœ€ๆ–ฐ็‰ˆๆœฌid var latest_version_id; // ๅฝ“ๅ‰็ผ–่พ‘็‰ˆๆœฌid var curr_version_id; //ๅฝ“ๅ‰็‰ˆๆœฌๅท var curr_version_num; $(function() { // ่Žทๅ–ๅฝ“ๅ‰ๆœ€ๆ–ฐ็‰ˆๆœฌ getLatestVersion(); // ็ป‘ๅฎšๅŠ ่ฝฝไธŠไธ€ไธช็‰ˆๆœฌไบ‹ไปถ $('#btn_prevV').click(prevVersionClick); // ็ป‘ๅฎšๅŠ ่ฝฝไธ‹ไธ€ไธช็‰ˆๆœฌไบ‹ไปถ $('#btn_nextV').click(nextVersionClick); // ็ป‘ๅฎšๆธ…็ฉบๅฝ“ๅ‰็ผ–่พ‘ๅŒบ $('#btn_clearCurr').click(clearCurrClick); // ็ป‘ๅฎšๆไบคไบ‹ไปถ $('#btn_subEditVsion').bind('click', submitNewVerFea); }); /** * ่Žทๅ–ๅฝ“ๅ‰ๆœ€ๆ–ฐ็‰ˆๆœฌ * * @returns */ function getLatestVersion() { $.ajax({ type : 'POST', url : '/latestRlseFetr.hms', dataType : 'json', success : function(response) { latest_version_id = response.releaseId; $('#txt_latestV').val(response.releaseNumber); fillVersionEditor(response); }, error : function(XMLHttpRequest, textStatus) { $.confirm({ title : 'ๅŠ ่ฝฝๆ–ฐ็‰ˆ็‰นๆ€งๅ‡บ้”™', content : textStatus + ' : ' + XMLHttpRequest.status, autoClose : 'ok|2000', type : 'red', buttons : { ok : { text : '็กฎ่ฎค', btnClass : 'btn-primary', }, } }); } }); } /** * ๅกซๅ……็‰ˆๆœฌไฟกๆฏ * @param versionArticle * @returns */ function fillVersionEditor(versionArticle){ //ๅ…ˆๆธ…็ฉบ clearCurrClick(); curr_version_id = versionArticle.releaseId; curr_version_num = versionArticle.releaseNumber; $('#txt_newV').val(versionArticle.releaseNumber); var relContent = versionArticle.releaseContent; relContent = relContent.match(/<p>(\S*)<\/p>/)[1]; relContent = relContent.split('</p><p>'); $('.version-input').each(function(i) { $(this).val(relContent[i].split('ใ€')[1]); }); } /** * ็ป‘ๅฎšๅŠ ่ฝฝไธŠไธ€ไธช็‰ˆๆœฌไบ‹ไปถ * * @returns */ function prevVersionClick() { //ๅฆ‚ๆžœ็‰ˆๆœฌ่ถ…่ฟ‡ๆœ€ๆ–ฐ๏ผŒ็›ดๆŽฅ่ฟ”ๅ›ž if(curr_version_id+1 > latest_version_id){ return; } $.ajax({ type : 'POST', url : '/latestRlseFetr.hms', dataType : 'json', data : { releaseId : curr_version_id+1, }, success : function(response) { fillVersionEditor(response); }, error : function(XMLHttpRequest, textStatus) { $.confirm({ title : 'ๅŠ ่ฝฝๆ–ฐ็‰ˆ็‰นๆ€งๅ‡บ้”™', content : textStatus + ' : ' + XMLHttpRequest.status, autoClose : 'ok|2000', type : 'red', buttons : { ok : { text : '็กฎ่ฎค', btnClass : 'btn-primary', }, } }); } }); } /** * ็ป‘ๅฎšๅŠ ่ฝฝไธ‹ไธ€ไธช็‰ˆๆœฌไบ‹ไปถ * * @returns */ function nextVersionClick() { //ๅฆ‚ๆžœ็‰ˆๆœฌๅฐไบŽ็ญ‰ไบŽ0๏ผŒ็›ดๆŽฅ่ฟ”ๅ›ž if(curr_version_id-1 <= 0){ return; } $.ajax({ type : 'POST', url : '/latestRlseFetr.hms', dataType : 'json', data : { releaseId : curr_version_id-1, }, success : function(response) { fillVersionEditor(response); }, error : function(XMLHttpRequest, textStatus) { $.confirm({ title : 'ๅŠ ่ฝฝๆ–ฐ็‰ˆ็‰นๆ€งๅ‡บ้”™', content : textStatus + ' : ' + XMLHttpRequest.status, autoClose : 'ok|2000', type : 'red', buttons : { ok : { text : '็กฎ่ฎค', btnClass : 'btn-primary', }, } }); } }); } /** * ็ป‘ๅฎšๆธ…็ฉบๅฝ“ๅ‰็ผ–่พ‘ๅŒบ * * @returns */ function clearCurrClick() { $('.version-input').each(function(i) { $(this).val(''); }); $('#txt_newV').val(''); } /** * ๆ–ฐ็‰ˆๆœฌ็‰นๆ€งๆไบค * * @returns */ function submitNewVerFea() { // ่Žทๅ–ๆ–‡็ซ ็ป†่Š‚ var article_data = JSON.stringify(articleDetail()); if (typeof (article_data) == 'undefined') { $.confirm({ title : 'ๆ”ถ้›†ๆ–ฐ็‰ˆ็‰นๆ€งๅ‡บ้”™', content : 'ๆ–ฐ็‰ˆ็‰นๆ€งๅ†…ๅฎนไธ่ƒฝไธบ็ฉบ', autoClose : 'ok|2000', type : 'red', buttons : { ok : { text : '็กฎ่ฎค', btnClass : 'btn-primary', }, } }); return; } $.ajax({ type : 'POST', async : false, url : '/editRlseFetr.hms', dataType : 'json', data : { type : $.trim($('#txt_newV').val()) != curr_version_num ? 'create' : 'modify', releaseId : curr_version_id, newArticle : article_data, }, success : function(response, status) { if (response == 1) { //ๅฆ‚ๆžœๆ˜ฏๆ–ฐๅปบ๏ผŒๆœ€ๆ–ฐ็‰ˆๆœฌๅทๅŠ 1 if($.trim($('#txt_newV').val()) != curr_version_num){ getLatestVersion(); } $.confirm({ title : 'ไธŠไผ ๆˆๅŠŸ', content : 'ๆ–ฐ็‰ˆ็‰นๆ€งไธŠไผ ๆˆๅŠŸ', autoClose : 'ok|2000', type : 'green', buttons : { ok : { text : '็กฎ่ฎค', btnClass : 'btn-primary', }, } }); } else { $.confirm({ title : 'ไธŠไผ ๅคฑ่ดฅ', content : 'ไธŠไผ ๅคฑ่ดฅ', autoClose : 'ok|2000', type : 'red', buttons : { ok : { text : '็กฎ่ฎค', btnClass : 'btn-primary', }, } }); } }, error : function(XMLHttpRequest, textStatus) { $.confirm({ title : 'ไธŠไผ ๅ‡บ้”™', content : textStatus + ' : ' + XMLHttpRequest.status, autoClose : 'ok|2000', type : 'red', buttons : { ok : { text : '็กฎ่ฎค', btnClass : 'btn-primary', }, } }); } }); } /** * ๆไบคๆ—ถ่Žทๅ–ๆ–ฐ็‰ˆ็‰นๆ€ง็ป†่Š‚ * * @returns */ function articleDetail() { var new_version_feature = {}; var version_feature = ''; $('.version-input').each(function(i) { if ($(this).val() != '') { version_feature += '<p>' + (i + 1) + 'ใ€' + $(this).val() + '</p>'; } }); // ๅฆ‚ๆžœๆ–ฐ็‰ˆ็‰นๆ€งไธบ็ฉบ๏ผŒ็›ดๆŽฅ่ฟ”ๅ›ž if (version_feature == '') { return; } new_version_feature.releaseAuthor = 'ไฝ•ๆ˜Ž่ƒœ'; new_version_feature.releaseDate = $.nowDateHMS(); new_version_feature.releaseNumber = $('#txt_newV').val(); new_version_feature.releaseContent = version_feature; return new_version_feature; }
Humsen/web/web-mobile/WebContent/js/personal_center/editor_version.js/0
{ "file_path": "Humsen/web/web-mobile/WebContent/js/personal_center/editor_version.js", "repo_id": "Humsen", "token_count": 2845 }
31
<link rel="stylesheet" href="/css/personal_center/modify-pwd.css"> <!-- ไฟฎๆ”น็”จๆˆทๅฏ†็ ่„šๆœฌ --> <script src="/js/personal_center/modify-pwd.js"></script> <form id="modifyPwdForm" class="form-horizontal modify-pwd-form"> <div class="form-group"> <label for="oldPassword" class="col-sm-2 control-label">ๆ—งๅฏ†็ </label> <div class="col-sm-8"> <input type="password" class="form-control" id="oldPassword" name="oldPassword" placeholder="่ฏท่พ“ๅ…ฅๆ—งๅฏ†็ " aria-describedby="helpBlock"> </div> <span id="helpBlock" class="help-block old-pwd-wrong-info">ๆ—งๅฏ†็ ่พ“ๅ…ฅ้”™่ฏฏ</span> </div> <div class="form-group"> <label for="newPassword" class="col-sm-2 control-label">ๆ–ฐๅฏ†็ </label> <div class="col-sm-8"> <input type="password" class="form-control" id="newPassword" name="newPassword" placeholder="่ฏท่พ“ๅ…ฅๆ–ฐๅฏ†็ "> </div> </div> <div class="form-group"> <label for="confirmPwd" class="col-sm-2 control-label">็กฎ่ฎคๆ–ฐๅฏ†็ </label> <div class="col-sm-8"> <input type="password" class="form-control" id="confirmPwd" name="confirmPwd" placeholder="่ฏท็กฎ่ฎคๆ–ฐๅฏ†็ "> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-8"> <a id="submitModifyPwd" class="btn btn-default" href="#" role="button">ๆไบค</a> </div> </div> </form>
Humsen/web/web-mobile/WebContent/personal_center/modify_pwd.html/0
{ "file_path": "Humsen/web/web-mobile/WebContent/personal_center/modify_pwd.html", "repo_id": "Humsen", "token_count": 586 }
32
/* * Editor.md * * @file editormd.logo.css * @version v1.5.0 * @description Open source online markdown editor. * @license MIT License * @author Pandao * {@link https://github.com/pandao/editor.md} * @updateTime 2015-06-09 */ /*! prefixes.scss v0.1.0 | Author: Pandao | https://github.com/pandao/prefixes.scss | MIT license | Copyright (c) 2015 */ @font-face { font-family: 'editormd-logo'; src: url("../fonts/editormd-logo.eot?-5y8q6h"); src: url(".../fonts/editormd-logo.eot?#iefix-5y8q6h") format("embedded-opentype"), url("../fonts/editormd-logo.woff?-5y8q6h") format("woff"), url("../fonts/editormd-logo.ttf?-5y8q6h") format("truetype"), url("../fonts/editormd-logo.svg?-5y8q6h#icomoon") format("svg"); font-weight: normal; font-style: normal; } .editormd-logo, .editormd-logo-1x, .editormd-logo-2x, .editormd-logo-3x, .editormd-logo-4x, .editormd-logo-5x, .editormd-logo-6x, .editormd-logo-7x, .editormd-logo-8x { font-family: 'editormd-logo'; speak: none; font-style: normal; font-weight: normal; font-variant: normal; text-transform: none; font-size: inherit; line-height: 1; display: inline-block; text-rendering: auto; vertical-align: inherit; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } .editormd-logo:before, .editormd-logo-1x:before, .editormd-logo-2x:before, .editormd-logo-3x:before, .editormd-logo-4x:before, .editormd-logo-5x:before, .editormd-logo-6x:before, .editormd-logo-7x:before, .editormd-logo-8x:before { content: "\e1987"; /* HTML Entity &#xe1987; example: <span class="editormd-logo">&#xe1987;</span> */ } .editormd-logo-1x { font-size: 1em; } .editormd-logo-lg { font-size: 1.2em; } .editormd-logo-2x { font-size: 2em; } .editormd-logo-3x { font-size: 3em; } .editormd-logo-4x { font-size: 4em; } .editormd-logo-5x { font-size: 5em; } .editormd-logo-6x { font-size: 6em; } .editormd-logo-7x { font-size: 7em; } .editormd-logo-8x { font-size: 8em; } .editormd-logo-color { color: #2196F3; }
Humsen/web/web-mobile/WebContent/plugins/editormd/css/editormd.logo.css/0
{ "file_path": "Humsen/web/web-mobile/WebContent/plugins/editormd/css/editormd.logo.css", "repo_id": "Humsen", "token_count": 1011 }
33
README.md exists but content is empty. Use the Edit dataset card button to edit it.
Downloads last month
39
Edit dataset card