锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
* @param obj 瑕佸鐞嗙殑鎺т歡, 鏀寔鏂囨湰鍩熷拰杈撳叆妗?br />
* @author
hotleave
*/
鎻愮ず錛氭?zhèn)?
鍙互鍏堜慨鏀歸儴鍒嗕唬鐮佸啀榪愯
鎻愮ず錛氭?zhèn)?
鍙互鍏堜慨鏀歸儴鍒嗕唬鐮佸啀榪愯
]]>
Once loaded, the editor registers a global object called FCKeditorAPI. This object offers the entry point to interact with any editor instance placed in a page.
NOTE: The FCKeditorAPI object will not be available during the page load. You need to wait for the editor to be loaded to use it.
Often, I see that people complain about a JavaScript error, “FCKeditorAPI is not defined”, when they try to use FCKeditorAPI.
For example
The following code will throw a JavaScript error when you try to use the FCKeditorAPI -
You can resolve the JavaScript error by adding a line of code (Line # 4) as shown below -
Hope this helps!
The NAME attribute cannot be set at run time on elements dynamically created with the createElement method. To create an element with a name attribute, include the attribute and value when using the createElement method.
鍚庢潵鎵懼埌鍥藉鐨勪竴綃囧笘瀛愶紝鎵懼埌涓涓В鍐蟲柟娉曪紝閭e氨鏄嬌鐢?a title="MSDN mergeAttributes Documentation" >mergeAttributes 鏂規(guī)硶錛屾ā鎷熸柊寤轟竴涓彧鏈塶ame涓嶅悓鐨勫厓绱狅紝騫跺拰涔嬪墠鐨勫厓绱犲悎騫訛紝榪欐牱灝辮兘杈懼埌閲嶅懡鍚嶇殑鏁堟灉浜嗐備唬鐮佸涓嬶細(xì)
var setElementName = function(el, newName) {
el = (typeof el === "string") ? document.getElementById(el) : el;
el.name = newName;
if(/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { // Internet Explorer test
el.mergeAttributes(document.createElement("<INPUT name='" + newName + "'/>"), false);
}
};
灞炴?/th> | 綾誨瀷 | Default | 鎻忚堪 | ||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
method | Array | 'post' | HTTP 璇鋒眰鏂瑰紡銆俫et or post | ||||||||||||||||||||||||||||||||||||||||||||||
parameters | String | '' | 鍦℉TTP璇鋒眰涓紶鍏ョ殑url鏍煎紡鐨勫煎垪琛ㄣ?/td> | ||||||||||||||||||||||||||||||||||||||||||||||
asynchronous | Boolean | true | 鎸囧畾鏄惁鍋氬紓姝?AJAX 璇鋒眰銆?/td> | ||||||||||||||||||||||||||||||||||||||||||||||
postBody | String | undefined | 鍦℉TTP POST鐨勬儏鍐典笅錛屼紶鍏ヨ姹備綋涓殑鍐呭銆?/td> | ||||||||||||||||||||||||||||||||||||||||||||||
requestHeaders | Array | undefined | 鍜岃姹備竴璧瘋浼犲叆鐨凥TTP澶撮儴鍒楄〃錛?榪欎釜鍒楄〃蹇呴』鍚湁鍋舵暟涓」鐩紝 浠諱綍濂囨暟欏圭洰鏄嚜瀹氫箟鐨勫ご閮ㄧ殑鍚嶇О錛? 鎺ヤ笅鏉ョ殑鍋舵暟欏圭洰浣胯繖涓ご閮ㄩ」鐩殑瀛楃涓插箋?渚嬪瓙:['my-header1', 'this is the value', 'my-other-header', 'another value'] | ||||||||||||||||||||||||||||||||||||||||||||||
onXXXXXXXX | Function(XMLHttpRequest) | undefined | 鍦ˋJAX璇鋒眰涓紝褰撶浉搴旂殑浜嬩歡/鐘舵佸艦鎴愮殑鏃跺欒皟鐢ㄧ殑鑷畾涔夋柟娉曘?渚嬪 var myOpts = {onComplete: showResponse, onLoaded: registerLoaded};. 榪欎釜鏂規(guī)硶灝嗚浼犲叆涓涓弬鏁幫紝 榪欎釜鍙傛暟鏄惡甯JAX鎿嶄綔鐨?XMLHttpRequest瀵硅薄銆?/td> | ||||||||||||||||||||||||||||||||||||||||||||||
onSuccess | Function(XMLHttpRequest) | undefined | 褰揂JAX璇鋒眰鎴愬姛瀹屾垚鐨勬椂鍊欒皟鐢ㄧ殑鑷畾涔夋柟娉曘?榪欎釜鏂規(guī)硶灝嗚浼犲叆涓涓弬鏁幫紝 榪欎釜鍙傛暟鏄惡甯JAX鎿嶄綔鐨?XMLHttpRequest瀵硅薄銆?/td> | ||||||||||||||||||||||||||||||||||||||||||||||
onFailure | Function(XMLHttpRequest) | undefined | 褰揂JAX璇鋒眰瀹屾垚浣嗗嚭鐜伴敊璇殑鏃跺欒皟鐢ㄧ殑鑷畾涔夋柟娉曘?榪欎釜鏂規(guī)硶灝嗚浼犲叆涓涓弬鏁幫紝 榪欎釜鍙傛暟鏄惡甯JAX鎿嶄綔鐨?XMLHttpRequest瀵硅薄銆?/td> | ||||||||||||||||||||||||||||||||||||||||||||||
insertion | Function(Object, String) | null | 涓轟簡鎶婅繑鍥炵殑鏂囨湰娉ㄥ叆鍒頒竴涓厓绱犱腑鑰屾墽琛岀殑鏂規(guī)硶銆?榪欎釜鏂規(guī)硶灝嗚浼犲叆涓や釜鍙傛暟錛岃琚洿鏂扮殑瀵硅薄騫朵笖鍙簲鐢ㄤ簬 Ajax.Updater 瀵硅薄涓簲鐢ㄣ?/td> | ||||||||||||||||||||||||||||||||||||||||||||||
decay | Number | undefined, 1 | 鍐沖畾褰撴渶鍚庝竴嬈″搷搴斿拰鍓嶄竴嬈″搷搴旂浉鍚屾椂鍦?function getContents() { var request_url = "test1.html"; // 闇瑕佽幏鍙栧唴瀹圭殑url var request_pars = '';//璇鋒眰鍙傛暟 var myAjax = new Ajax.Updater('result', request_url,{ // 灝唕equest_url榪斿洖鍐呭緇戝畾鍒癷d涓簉esult鐨勫鍣ㄤ腑 method : 'get', //HTTP璇鋒眰鐨勬柟娉?get or post parameters : request_pars, //璇鋒眰鍙傛暟 onFailure : reportError, //澶辮觸鐨勬椂鍊欒皟鐢?nbsp;reportError 鍑芥暟 onLoading : loading, //姝e湪鑾峰緱鍐呭鐨勬椂鍊?nbsp; onComplete : done //鍐呭鑾峰彇瀹屾瘯鐨勬椂鍊?nbsp; }); } function loading() { $('loading').style.display = 'block'; } function done() { $('loading').style.display = 'none'; } function reportError(request) { alert('Sorry. There was an error.'); } Ajax.Updater 涓烘垜浠彁渚涘姞杞芥枃妗f椂鍊欑殑涓夌鐘舵? onComplete,onLoading,onFailure.鎴戜滑鍙互鑷畾涔変竴涓嚱鏁板垎鍒浉搴旇繖涓夌涓嶅悓鐨勭姸鎬併?br /> 涓嬮潰鐨勪緥瀛愮敤鍒頒簡success (涓鍒嘜K鐨勬椂鍊欐墠琚敤鍒? 錛屽拰瀹冨悓絳夊湴浣嶇殑灞炴ц繕鏈変竴涓?font face="Courier New">failure (鏈夊湴鏂瑰嚭闂鐨勬椂鍊欒鐢ㄥ埌) 榪欓噷娌$敤鍒般傚嚭閿欐椂鍦?onFailure 澶勮皟鐢?reportError 鏂規(guī)硶銆?br /> <script>
function getHTML() { var url = 'http://yourserver/app/getSomeHTML'; var pars = 'someParameter=ABC'; var myAjax = new Ajax.Updater( {success: 'placeholder'}, url, {method: 'get', parameters: pars, onFailure: reportError}); } function reportError(request) { alert('Sorry. There was an error.'); } </script> <input type=button value=GetHtml onclick="getHTML()"> <div id="placeholder"></div> ]]> This topic contains the following sections.
IntroductionMany Web designers use browser detection techniques to ensure that their sites display properly when viewed with specific browsers. Some browser detection techniques encounter problems when viewed with later versions of the browser they're tailored for. For example, many Web designers used Cascading Style Sheets (CSS) rules that relied on the implementation of CSS in Microsoft Internet Explorer 6 to detect that version of the browser. When Internet Explorer 7 provided additional support for the CSS, Level 2 (CSS2) standard, many of these rules (also known as "CSS hacks") failed to detect the new version of the browser. As a result, sites that relied on these rules no longer displayed as intended. When using browser detection techniques, use techniques that support current and future versions of the browser you're targeting. This topic examines four different ways to detect Internet Explorer and also provides a brief look at alternatives to browser detection. Advantages of each technique are reviewed and suggestions are offered for effective use. In addition, examples demonstrate techniques that support current and future versions of Internet Explorer. Parsing the User-Agent StringThe most common way to detect Internet Explorer is to use client-side scripting to parse the user-agent string and extract the version number from the version token. The following example shows the preferred way to do this with JavaScript. function getInternetExplorerVersion() As you review this example, please note the following:
This example properly detects most versions of Internet Explorer, but only if scripting is enabled. However, the user-agent string is dynamic; it can be changed by the end user, by browser extensions, and by operating system updates. As a result, there's no guarantee that the user-agent string accurately reflects the browser being used. The next sections show techniques that may be more effective alternatives.
Note It is not recommended that you block access to content
based on the user-agent string of the browser. If you do have to offer
different content to different versions of the browser due to improved
capabilities, you want to ensure that future versions of the browser are
not blocked. Serving content based solely on the user-agent string is
often an unreliable way to detect the full capabilities of the browser.
For more information about the user-agent string and Internet Explorer's user-agent tokens, see Understanding User-Agent Strings. Using Conditional CommentsIf you are specifically interested in Internet Explorer, conditional comments might be a more appropriate choice. The following example shows an effective way to use conditional comments to display custom content. <!--[if gte IE 8]> Like the earlier JavaScript example, this example makes sure the current version is greater than or equal to a specified version number. This ensures that the content designed for the current version of the browser is properly displayed in a future version. This example carefully combines downlevel-revealed and downlevel-hidden conditional comments to ensure that each message appears only for the intended browsers. Because conditional comments do not rely on JavaScript, they are effective even if the user has disabled scripting. Unlike the user-agent string, conditional comments are typically updated when the browser is upgraded. This makes them more reliable than user-agent strings. However, because no other browser currently supports conditional comments, they are limited to Internet Explorer. Depending on your needs, this may be an advantage or a disadvantage. For more information about conditional comments, see About Conditional Comments. Detecting FeaturesFor many Web sites, detecting a browser's features is the preferred form of browser detection because it allow the Web developer to focus on the general capabilities of a browser, rather than the specific details of each browser release. The following example demonstrates a simple form of feature detection. if (XMLHttpRequest) Feature detection tends to support a broader range of browsers. In addition, should a browser implement the feature you're interested in, your content will be delivered without requiring changes to your browser detection technique. As a result, techniques that focus on features tend to require less maintenance than techniques that rely on environmental factors, such as the user-agent string. In addition, they tend to work across a wider variety of browser devices, including screen readers, mobile devices, and so on. Use care when creating or using browser detection techniques that attempt to detect a browser based on unsupported functionality. If a future version of the browser implements the missing feature, it's entirely possible your site may not display as intended. Using the ASP.NET HttpBrowserCapabilities ObjectASP.NET developers can use the HttpBrowserCapabilities object to detect and respond to almost any browser. In addition, alternate content is not sent to the end-user's browser. The following example shows how to detect Internet Explorer from an ASP.NET application using C#. private float getInternetExplorerVersion() Because the HttpBrowserCapabilities object parses the user-agent string for you, you can use the MajorVersion and MinorVersion properties to determine the current version of the browser. Unlike the JavaScript examples, these properties are numeric; MajorVersion returns an integer value, and MinorVersion returns a double value. Depending on the language used to implement your ASP.NET application, however, you might still have to typecast these property values to the data type you're using. To illustrate, the C# example converts MajorValue to the floating point value returned by the function. For more information about the HttpBrowserCapabilities
object, see HOW TO: Determine the Browser Version in ASP.NET or Browser Sniffing in ASP.NET Alternatives to Browser DetectionIf you use browser detection because Internet Explorer doesn't appear to support a particular feature, an alternate approach may be more effective. Before implementing new (or revising existing) browser detection, it may be worthwhile to consider one of the following approaches to solve the underlying problem.
SummaryIf you must detect the browsers that view your Web sites, follow effective practices: plan for future browser releases, convert values appropriately, and design techniques to fail gracefully. Doing so will reduce the long-term maintenance of your site and help ensure that your site functions properly when viewed with newer versions of Internet Explorer and other browsers. Bad browser detection
Using "v to detect IE is a bad idea because this will not
work if future versions of IE change this behavior. The officially
supported detection methods should be used.
However this example from the article is misleading. Since other browsers don't support conditional comments [if !IE] results in comments that will show up in no browsers. <![if !IE]> <p>You're not using Internet Explorer.</p> <![endif]> How
to detect IE8 using JavaScript
Check out:
http://blogs.msdn.com/giorgio/archive/2009/04/14/how-to-detect-ie8-using-javascript-client-side.aspx Shortest
way of detecting IE
More efficient way to detect any version of IE is function isMSIE() {
]]>
|
Properties | Description |
---|---|
appCodeName | The code name of the browser. |
appName | The name of the browser (ie: Microsoft
Internet Explorer ). |
appVersion | Version information for the browser
(ie: 4.75 [en] (Win98; U) ). |
cookieEnabled | Boolean that indicates whether the browser has cookies enabled. |
language | Returns the default language of the
browser version (ie: en-US ). NS and Firefox
only. |
mimeTypes[] | An array of all MIME types supported by the client. NS and Firefox only. |
platform[] | The platform of the client's computer
(ie: Win32 ). |
plugins | An array of all plug-ins currently installed on the client. NS and Firefox only. |
systemLanguage | Returns the default language of the operating system
(ie: en-us ). IE only. |
userAgent | String passed by browser as user-agent
header. (ie: Mozilla/4.0 (compatible; MSIE 6.0;
Windows NT 5.1) ) |
userLanguage | Returns the preferred language setting of
the user
(ie: en-ca ). IE only. |
Let's see exactly what these properties reveal of the browser you're currently using:
appCodeName: Mozilla
appName: Netscape
appVersion:
5.0 (Windows; zh-CN)
userAgent: Mozilla/5.0 (Windows; U;
Windows NT 6.1; zh-CN; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
platform:
Win32
At a glance at the above table, you may be swayed towards turning to the following two properties to do your browser detection bidding:
navigator.appName
navigator.appVersion
After all, you are trying to detect a browser's
name and
version right? However, they both will most likely mislead you. In
browsers such as various versions of Netscape and Firefox, these two
properties return simply "Netscape" for appName
, and 5.0
for appVersion
without any further distinction for
Firefox
and its version, and hence are pretty much useless in the real world.
For example, in both Firefox 1.x and Firefox 2.x, these two properties
return:
appName: Netscape
appVersion: 5.0 (Windows; en-US)
We need to turn to a property that's more thorough
in its
investigative work if we want more consistency and accuracy, and that
turns out to be navigator.userAgent
.
In Firefox 2.0.0.13 for example,
the userAgent
property reads:
UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13
The detail we're interested in apparently lies at
the very
end, or Firefox/2.0.0.13
. Different versions of Firefox
will
contain a different version number, but the pattern is consistent
enough.
The part we're interested in occurs after the string "Firefox/
",
or the exact version number. There are many ways to get to it using
either
standard String
or RegExp
methods- I'm opting for the later here:
<script type="text/javascript">
if (/Firefox["/"s]("d+"."d+)/.test(navigator.userAgent)){ //test for
Firefox/x.x or Firefox x.x (ignoring remaining digits);
var ffversion=new Number(RegExp.$1) // capture x.x portion and store
as
a number
if (ffversion>=3)
document.write("You're using FF 3.x or above")
else if (ffversion>=2)
document.write("You're using FF 2.x")
else if (ffversion>=1)
document.write("You're using FF 1.x")
}
else
document.write("n/a")
</script>
Output: You're using FF 3.x or above
Basically, I'm capturing just the versonMajor.versionMinor portion of the full version number of Firefox (ie: 2.0.0.13 becomes simply 2.0), and using that as basis to detect the various versions of Firefox. Delving any deeper, and the returned version may no longer be a number but a string (ie: 2.0.0), which makes numeric comparisons cumbersome.
In IE 7.0 for example,
the userAgent
property reads:
UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)
So the part we're interested in lies in the
middle, or
MSIE 7.0;
. If you try a shortcut and use
parseFloat
on the entire string to get to the 7.0
portion, it won't
work. This
is due to the way parseFloat
works- by returning the
first number it
encounters, which in this case is 4.0. Once again we need to use
either
standard
String or
RegExp methods again to get to the actual version number; below
I'm
using RegExp as well:
<script type="text/javascript">
if (/MSIE ("d+"."d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
if (ieversion>=8)
document.write("You're using IE8 or above")
else if (ieversion>=7)
document.write("You're using IE7.x")
else if (ieversion>=6)
document.write("You're using IE6.x")
else if (ieversion>=5)
document.write("You're using IE5.x")
}
else
document.write("n/a")
</script>
Output: n/a
Detecting Opera using the navigator
object at
first appears to be tricky business due to the browser's identity
crisis. You see, Opera 8 and below by default identifies itself as IE6
(or lower) in the navigator
object. Users can override
this
setting under "Edit Site Settings" in the toolbar to identify as
Opera or even another browser instead. Starting in Opera 9, the
browser
regains its confidence and identifies by default as itself, Opera,
though users can still modify this setting manually in the toolbar.
The
bottom line is, Opera can appear as either Opera, Internet Explorer,
or
another browser within a designated list in the navigator
object.
Lets take a
look at what navigator.userAgent
in Opera 8.5 returns
depending on what it has chosen to identify itself as (whether
automatically or manually):
As IE6: Mozilla/4.0 (compatible; MSIE
6.0; Windows XP) Opera 8.5
[en]
As Moz5: Mozilla/5.0 (Windows XP;
U) Opera 8.5 [en]
As Opera: Opera/8.5 (Windows
XP; U) [en]
Notice how if it's set to identify as IE, MSIE 6.0
appears
within the string, while if set to identify as Mozilla,
Mozilla/5.0
appears instead. As Opera itself, Opera/8.5
appears. In all three cases, the one commonality that we can exploit
to
actually detect Opera and its true version regardless of which
identify
it's decided to take on is the string "Opera x.x
" or "Opera/x.x
"
within navigator.userAgent
. In other words, there are two
versions of the target string we need to be aware of. With that said,
here's how you might go about testing for a specific version of Opera,
which turns out to be no different than the technique used for
detecting, say, Firefox:
<script
type="text/javascript">
//Note: userAgent in Opera9.24 WinXP returns: Opera/9.24 (Windows NT
5.1; U;
en)
// userAgent in Opera
8.5 (identified as IE) returns: Mozilla/4.0 (compatible; MSIE 6.0;
Windows
NT 5.1) Opera 8.50 [en]
// userAgent in Opera
8.5 (identified as Opera) returns: Opera/8.50 (Windows NT 5.1; U) [en]
if (/Opera["/"s]("d+"."d+)/.test(navigator.userAgent)){ //test for
Opera/x.x
or Opera x.x (ignoring remaining decimal places);
var oprversion=new Number(RegExp.$1) // capture x.x portion and store
as a
number
if (oprversion>=10)
document.write("You're using Opera 10.x or above")
else if (oprversion>=9)
document.write("You're using Opera 9.x")
else if (oprversion>=8)
document.write("You're using Opera 8.x")
else if (oprversion>=7)
document.write("You're using Opera 7.x")
else
document.write("n/a")
}
else
document.write("n/a")
</script>
Output: n/a
We've seen how to use navigator to detect the browser type of your visitors. If the potential pitfalls and complexity of usage of it is a little too much for you, an alternative is to use Object Detection. Whichever method you choose, just be sure to choose one!
var setName = function(el, newName) {
el = (typeof el === "string") ? document.getElementById(el) : el;
el.name = newName;
if (/*@cc_on!@*/0) { // Internet Explorer test (needs to be modified for IE8)
el.mergeAttributes(document.createElement("<INPUT name='" + newName + "'/>"), false);
}
};
In Mootools 1.2.1:
var setName = function(elementId, newName) {
var el = (!!elementId) ? $(elementId) : null;
if (!elementId || !newName || !el) return;
el.set({ "name" : newName });
if (Browser.Engine.trident4 || Browser.Engine.trident5) {
el.mergeAttributes(document.createElement("<INPUT name='" + newName + "'/>"), false);
}
};
Before OUTERHTML:
<INPUT id=renameTarget value="Set Random Name" type=submit>
I discovered a real JavaScript gem in PHPMyAdmin this morning. They have code that inserts content into a <textarea> at the cursor position instead of just at the beginning/end of the content. This is something I thought wasn’t possible – I’m quite pleased I was wrong.
I’ll be glad to see this code spread quickly to web forms that use buttons to aid in styling text and inserting image and link tags. WordPress and other blog and web forum packages would really benefit from this. (PHPMyAdmin is GPL, so any other GPL app should be able to use their code directly with attribution).
Here is a quick look at a generic version of the technique:
function insertAtCursor(myField, myValue) {
//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos,
myField.value.length);
} else {
myField.value += myValue;
}
}
// calling the function
insertAtCursor(document.formName.fieldName, 'this value');
15涓紭縐鐨刯Query鍥劇墖騫葷伅鐗?鐢誨粖鏁堟灉錛屽熀鏈兘宸茬粡鍖呭惈浜嗗師鎻掍歡鐨勫彂甯冨湴鍧銆佷嬌鐢ㄦ柟娉曞拰婧愪唬鐮佷笅杞姐?/p>
Galleriffic 鏄嬌鐢? Mike Alsup 鐨?jQuery Cycle plugin 鍒涘緩鐨勫浘鐗囧睍紺烘晥鏋滐紝鍖呮嫭緙╃暐鍥俱佸浘鐗囨爣棰樺拰鎻忚堪絳夎緇嗗姛鑳斤紝鏄竴涓潪甯鎬笉閿欑殑楂樿川閲忕敾寤婄浉鍐屽睍紺哄伐鍏楓?/p>
zoomimage 錛屼互涓縐嶇嫭鍏烽瓍鍔涚殑鏂瑰紡灞曠ず鍥劇墖鏁堟灉銆傜緝鐣ュ浘閾炬帴鍦ㄦ湰欏靛脊鍑哄ぇ鍥撅紝騫朵笖鍙互鍙互闅忔剰鎷栨嫿璇ユ?zhèn)瑡巩鍥剧墖銆?/p>
Easy Slider 鍙互瀹炵幇鍥劇墖鎴栧叾浠栦換鎰忓唴瀹癸紝鍦ㄦ按騫蟲垨鍨傜洿鏂瑰悜涓婄殑婊戝姩鏁堟灉錛屼綘榪樺彲浠ラ氳繃 CSS 鑷畾涔夎緗牱寮忋?/p>
涓涓簮鑷編鍥芥葷粺 Barack Obama 緗戠珯鐨勫瀭涓嬫粦鍔ㄨ彍鍗曟帶鍒剁殑鍥劇墖騫葷伅鏁堟灉銆?/p>
CodaSlider錛? 鍙堜竴涓笉閿欑殑婊戝姩鎺у埗鏁堟灉銆?/p>
jQuery Slider II 鐨勫竷灞闈炲父絎﹀悎鎿嶄綔涔?fàn)鎯Q屽湪搴曢儴鍒楀嚭甯︽粴鍔ㄦ潯鐨勭緝鐣ュ浘鎺у埗鍒楄〃錛岀劧鍚庡湪涓婇潰鏄劇ず瀵瑰簲鍥劇墖鐨勫ぇ鍥炬祻瑙堬紝闈炲父閫傚悎鍋氶珮綰х浉鍐屻?/p>
Beautiful Slider錛? 鍏夌湅榪欎釜鏁堟灉鍥句綘灝辯煡閬撹繖涓彃浠舵湁澶氭浜嗗惂錛屾槸鐨勶紝榪欎釜鎻掍歡瀹炵幇鐨勬晥鏋滃凡緇忎笉閫婅壊浜嶧lash瀹屾垚鐨勬晥鏋滐紝鏁翠綋琛ㄧ幇嫻佺晠錛屾枃瀛楁樉紺烘晥鏋滄洿鏄垱鎰忕嫭鐗廣?/p>
loopedSlider鏄張涓涓換鎰忓唴瀹規(guī)粴鍔? 鍒囨崲鐨勫夠鐏墖鎻掍歡錛屼嬌鐢ㄦ搷浣滅畝鍗曘?/p>
SpaceGallery鏄竴涓叏鏂扮殑jQuery鎻掍歡錛岀偣鍑誨綋 鍓嶅浘鐗囷紝浼?xì)鑷姩鏀惧ぇ娑堝け锛屽悓鏃跺悗闈㈢殑鍥剧墖鍚戝墠灞暯C猴紝鏈変竴縐嶆椂鍏夋満鍣ㄧ殑鎰熻銆?/p>
SmoothGallery鏄竴涓渶濂界殑 Javascript 騫葷伅鐗囨晥鏋滀箣涓錛屽彲浠ュ疄鐜板悇縐嶄笉鍚岀殑騫葷伅鐗囪漿鎹㈡晥鏋溿?/p>
jQuery Multimedia Portfolio鏄竴涓熀浜巎Query 鐨勬粦鍔ㄦ晥鏋滄彃浠?闄や簡鍙互灞曠ず鍥劇墖涔嬪錛岃繕鍙互鍔犲叆鍚勭涓嶅悓綾誨瀷鐨勫濯掍綋鏂囦歡銆?/p>
s3Slider鏄竴涓潪甯哥畝鍗曞疄鐢ㄧ殑嫻佺晠騫葷伅鐗囨晥鏋滐紝榪欎釜
鎻掍歡琚簲鐢ㄥ湪鏃犳暟鐨刉ordPress涓撲笟涓婚妯℃澘涓?/p>
javascript 瀛楃涓插鐞?/strong>
鏂囩珷鏉ユ簮錛?a target="_blank">http://lmgq.vip.sina.com/tech/jsadvancedlesson/c2p1.htm
涓銆佸0鏄庡瓧絎︿覆:
var normal_monkey = "I am a monkey!<br>";
document.writeln("Normal monkey " + normal_monkey);
var bold_monkey = normal_monkey.bold();
document.writeln("Bold monkey " + bold_monkey);
榪欓噷鐨勫0鏄庯細(xì) var bold_monkey = normal_monkey.bold();
鍜屼笅闈㈠澹版槑鏄瓑鍚岀殑錛?nbsp;
var bold_monkey = "<b>" + normal_monkey + "</b>";
絎?涓増鏈殑澹版槑鐪嬭搗鏉ヨ綆鏄庡緱澶氥傝繖閲岀敤鍒頒簡瀛楃涓插璞′腑
鐨刡old瀵硅薄錛屽叾浠栫殑瀛楃涓插璞¤繕鏈塱ndexOf, charAt,
substring, 浠ュ強(qiáng)split, 榪欎簺鏂規(guī)硶鍙互娣卞叆瀛楃涓茬殑緇勬垚緇撴瀯銆?br />
棣栧厛鎴戜滑鐮旂┒涓涓媔ndexOf銆?/p>
2銆乮ndexOf
indexOf鐢ㄤ簬鍙戠幇涓緋誨垪鐨勫瓧絎﹀湪涓涓瓧絎︿覆涓瓑浣嶇疆騫跺憡璇変綘瀛愬瓧絎︿覆鐨勮搗濮嬩綅緗傚
鏋滀竴涓瓧絎︿覆涓儴鍖呭惈璇ュ瓙瀛楃涓插垯indexOf榪斿洖returns "-1."
渚嬪瓙錛?br />
var the_word = "monkey";
//璁╂垜浠粠鍗曡瘝 "monkey"寮濮嬨?nbsp;
var location_of_m = the_word.indexOf("m");
//location_of_m(瀛楁瘝m鐨勪綅緗?灝嗕負(fù)0錛屽洜涓哄瓧姣峬浣嶄簬璇ュ瓧絎︿覆鐨勮搗濮嬩綅緗?br />
var location_of_o = the_word.indexOf("o");
//location_of_o(瀛楁瘝o鐨勪綅緗?灝嗕負(fù)1銆?br />
var location_of_key = the_word.indexOf("key");
//location_of_key(key鐨勪綅緗?灝嗕負(fù)3鍥犱負(fù)瀛愬瓧絎︿覆“key”浠ュ瓧姣峩寮濮嬶紝鑰宬
鍦ㄥ崟璇峬onkey涓殑浣嶇疆鏄?銆?br />
var location_of_y = the_word.indexOf("y");
//location_of_y)瀛楁瘝y鐨勪綅緗?鏄?銆?nbsp;
var cheeky = the_word.indexOf("q");
//cheeky鍊兼槸-1錛屽洜涓哄湪鍗曡瘝“monkey”涓病鏈夊瓧姣峲銆?/p>
indexOf鏇村疄鐢ㄤ箣澶?
var the_email = prompt("What’s your email address?", "");
var the_at_is_at = the_email.indexOf("@");
if (the_at_is_at == -1)
{
alert("You loser, email addresses must
have @ signs in them.");
}
榪欐浠g爜璇㈤棶鐢ㄦ埛鐨勭數(shù)瀛愰偖浠跺湴鍧錛屽鏋滅敤鎴瘋緭鍏ョ殑鐢?shù)瀛愰偖錃g鍦板潃涓笉鍖呭惈瀛楃 鍒?nbsp;鎻?/p>
紺虹敤鎴鳳紓錛犱綘杈撳叆鐨勭數(shù)瀛愰偖浠跺湴鍧鏃犳晥錛岀數(shù)瀛愰偖浠剁殑鍦板潃蹇呴』鍖呭惈瀛楃@銆傦紓
3銆乧harAt
chatAt鏂規(guī)硶鐢ㄤ簬鍙戠幇涓涓瓧絎︿覆涓煇涓壒瀹氫綅緗殑瀛楃銆?br />
榪欓噷鏄竴涓緥瀛愶細(xì)
var the_word = "monkey";
var the_first_letter = the_word.charAt(0);
var the_second_letter = the_word.charAt(1);
var the_last_letter = the_word.charAt(the_word.length-1);
the_first_letter(絎?涓瓧絎?鏄?m"
the_second_letter(絎?涓瓧絎?鏄?o"
the_last_letter(鏈鍚庝竴涓瓧絎?鏄?nbsp;"y"
娉ㄦ剰鍒╃敤瀛楃涓茬殑length(闀垮害)灞炴т綘鍙互鍙戠幇鍦ㄥ寘鍚灝戜釜瀛楃銆傚湪鏈緥涓紝
the_word鏄?monkey"錛屾墍浠he_word.length鏄?銆備笉瑕佸繕璁板湪涓涓瓧絎︿覆涓1涓瓧絎︾殑
浣嶇疆鏄?錛屾墍浠ユ渶鍚庝竴涓瓧絎︾殑浣嶇疆灝辨槸length-1銆傛墍浠ュ湪鏈鍚庝竴琛屼腑鐢ㄤ簡
the_word.length-1銆?gt;>
4銆佸瓙瀛楃涓詫紙substring錛?br /> 瀛愬瓧絎︿覆錛坰ubstring錛夊拰charAt鏈変簺璞★紝涓嶅悓涔嬪鍦ㄤ簬瀹冭兘澶熶粠涓涓崟璇嶄腑鎶撳彇鏁翠釜鐨?/p>
瀛愬瓧絎︿覆錛岃屼笉鍙槸瀛楁瘝錛岃繖閲屾槸鍏舵牸寮忥細(xì)
var the_substring = the_string.substring(from, to);
"From"鎸囩殑鏄瓙瀛楃涓蹭腑絎紤涓瓧姣嶇殑浣嶇疆錛?to"鏈夌偣濂囩壒錛屽畠鏄瀛愬瓧絎︿覆涓瘮鏈鍚?/p>
涓涓綅緗ぇ錛戠殑浣嶇疆錛庝嬌鐢ㄨ繖縐嶇濂囩殑鏂規(guī)硶浣犲彲浠ユ爣璁板瓙瀛楃涓茬殑璧峰鍜岀粨鏉熶綅緗紝鐢?/p>
"to"鐨勪綅緗噺鍘?from"鐨勪綅緗氨浼?xì)寰楀國櫙ュ瓙瀛椊W︿覆鐨勯暱搴︼細(xì)
var the_string = "monkey";
var clergy = the_string.substring(0,4);
var tool = the_string.substring(3,6);
榪愯璇ユ浠g爜鍚庡彉閲廲lergy鐨勫間負(fù)"monk"; 鍙橀噺tool鐨勫間負(fù)"key"銆?/p>
瀛愬瓧絎︿覆甯稿拰indexOf涓璧蜂嬌鐢紝灝嗗瓧絎︿覆鍒嗘垚鑻ュ共鍧楋紟渚嬪錛?br /> 浣犲彲浠ヤ粠涓涓粰瀹氱殑URL涓娊鍙栧嚭鍏跺煙鍚嶏細(xì)
var the_url = prompt("What’s the URL?","");
var lead_slashes = the_url.indexOf("http://");
var domain_start = lead_slashes + 2;
var without_resource = the_url.substring(domain_start, the_url.length);
var next_slash = without_resource.indexOf("/");
var domain = without_resource.substring(0, next_slash);
榪欐浠g爜鐨勬剰鎬濇槸錛氬鏋滀綘杈撳叆
"http://www.webmonkey.com/javascript/index.html";錛屽垯鍩熷悕
灝辨槸
"www.webmonkey.com" 錛庡鏋滆繖涓柟娉曞浣犳潵璇存湁浜涢夯鐑︼紝鎴戝皢鍚戜綘浠嬬粛濡備綍浣跨敤split
鏂規(guī)硶綆鍖栧叾鎵ц榪囩▼錛庝絾鏄鍏堟垜浠綔涓浜涘垎鏋愶紟
鍩烘湰鐨勬妧宸ф槸灝嗙錛戜釜鏂滄潬鍜岀錛掍釜鏂滄潬涔嬮棿鐨勫唴瀹瑰垎紱誨嚭鏉ワ細(xì)
var the_url = prompt("What’s the URL?","");
//榪欒浠g爜鍚戠敤鎴瘋闂竴涓猆RL錛庡亣璁劇敤鎴瘋緭鍏ヤ簡
"http://www.webmonkey.com/javascript/index.html.";
var lead_slashes = the_url.indexOf("http://");
榪欒浠g爜紜畾絎竴涓弻鏂滄潬鐨勪綅緗紟鍦ㄦ湰渚嬩腑lead_slashes鐨勫兼槸錛曪紝鍥犱負(fù)鍙屾枩鏉犵殑浣?/p>
緗粠錛曞紑濮嬶紟
浣犲彲鑳戒細(xì)鎯籌紝閫氬父鐨刄RL閮芥槸浠ttp://寮濮嬶紝鎵浠ュ弻鏂滄潬鐨勪綅緗偗瀹氭槸鍦紩寮濮嬶紝涓轟粈
涔堣繕瑕佸姞鍏ndexOf榪欎竴孌靛浣欑殑浠g爜鍛紵浣嗘槸闂鐨勫叧閿湪浜庝綘涓嶇煡閬撶敤鎴峰湪濉叆URL
鏃舵槸鍚︿竴瀹氬~鍏ttp:錛屼粬浠篃璁鎬細(xì)涓嶅皬蹇冨閿叆浜嗕竴涓┖鏍鹼紝涔熻浠栦滑鎵閿叆鐨刄RL鍦?/p>
涓涓姞瀵嗘湇鍔″櫒涓婏紝鍏禪RL鏄?https://www.whatever.com/"; 錛? 鍦ㄧ紪紼嬩綘蹇呴』棰勬枡鍒扮縐?/p>
鍙兘鍙戠敓鐨勯棶棰橈紟鎵浠ユ垜浠繀欏葷敤indexOf鏂規(guī)硶紜畾鍙屾枩鏉犵殑紜垏鐨勮搗濮嬩綅緗紟
var domain_start = lead_slashes + 2;
榪欒浠g爜鐢ㄤ簬璁$畻璇ュ煙鍚嶇殑絎紤涓瓧姣嶇殑璧峰浣嶇疆錛庣敱浜庤繖閲屾湁涓涓弻鏂滄潬錛屾墍浠ュ煙鍚?/p>
絎紤涓瓧姣嶇殑璧峰浣嶇疆搴旇鍦ㄥ弻鏂滄潬鎵鍦ㄤ綅緗姞錛掔殑浣嶇疆錛?/p>
var without_resource = the_url.substring(domain_start, the_string.length);
榪欐浠g爜灝嗗煙鍚嶈搗濮嬩綅緗線鍚庣殑鎵鏈夊瓧絎﹂兘鎻愬彇鍑烘潵錛庢墍浠ユ墽琛屽畬榪欒浠g爜鍚?/p>
without_resource鏄?www.webmonkey.com/javascript/index.html."
var next_slash = without_resource.indexOf("/");
榪欒浠g爜璁$畻鍑鴻瀛楃涓蹭腑涓嬩竴涓枩鏉犵殑浣嶇疆錛岃屼粠璇ュ瓧絎︿覆璧峰浣嶇疆鍒拌繖涓枩鏉犱箣闂?/p>
鐨勫唴瀹瑰氨鏄煙鍚嶏紟鍦ㄦ湰渚嬩腑涓嬩竴涓枩鏉犵殑浣嶇疆鏄?7銆?/p>
var domain = without_resource.substring(0, next_slash);
鏈鍚庝竴姝ユ槸鎻愬彇鍑鴻瀛楃涓茶搗濮嬩綅緗埌涓嬩竴涓枩鏉犱箣闂寸殑鎵鏈夊唴瀹癸紟鍦ㄦ湰渚嬩腑浣垮緱鍩熷悕
絳夊悓浜?www.webmonkey.com"銆?/p>
榪欐牱鍋氱‘瀹炲緢楹葷儲錛屽埄鐢╯plit鏂規(guī)硶鍒欏彲浠ヤ嬌璇ヨ繃紼嬪鏄撳緢澶氾紟>>
5銆佸垎鍓叉柟娉?splitting method)
浣犲彲浠ヤ嬌鐢╯plit鏂規(guī)硶鐢ㄩ檺浣嶅櫒鏉ュ垎鍓蹭竴緋誨垪鐨勫悕縐幫紝鐒跺悗灝嗗叾
鏀懼湪涓涓暟緇勪腑錛庝緥濡傦細(xì)
var my_friends ="trixie,moxie,sven,guido,hermes";
var friend_array =my_friends.split(",");
for (loop=0; loop < friend_array.length;loop++)
{ document.writeln(friend_array[loop] + " is myfriend.<br>");}
榪欐浠g爜灝嗗瓧絎︿覆my_friends鍒嗗壊鎴愬寘鍚紩涓厓绱犵殑鏁扮粍錛嶫avaScript鍙互涓轟綘鑷姩寤?/p>
绔嬩竴涓暟緇勶紝鎵浠ヤ綘鏃犻渶浣跨敤new Array()錛?/p>
灝嗗瓧絎︿覆鍒嗗壊鎴愭暟緇勪箣鍚庯紝鎴戜滑浣跨敤浜嗗驚鐜鍙ュ啓鍑烘瘡涓涓悕縐幫紟鎴戜滑鍙互鍒╃敤split鏂?/p>
娉曠畝鍖栧墠闈㈡墍璁插埌鐨勫煙鍚嶆彁鍙栵細(xì)
var the_url = prompt("What’s the URL?","");
var first_split = the_url.split("http://");
var without_resource = first_split[1];
var second_split = without_resource.split("/");
var domain = second_split[0];
榪欐浠g爜綆鍖栦簡寰堝鑰屼笖涔熸洿瀹規(guī)槗鐞嗚В錛庢垜浠潵鍒嗘瀽涓浜涜繖孌典唬鐮侊細(xì)
var the_url = prompt("What’s the URL?","");
鎻愮ず鐢ㄦ埛杈撳叆涓涓猆RL錛屽亣璁劇敤鎴瘋緭鍏?br />
"http://www.webmonkey.com/javascript/index.html"; 錛?br />
var first_split = the_url.split("http://");
灝嗙敤鎴瘋緭鍏ョ殑瀛楃涓插垎鍓叉垚涓ゅ潡錛歠irst_split[0]鏄?http:"錛宖irst_split[1]鏄?/p>
"www.webmonkey.com/javascript/index.html."
var without_resource = first_split[1];
//鎻愬彇鍑烘暟緇勪腑鐨勭錛掍釜鍏冪礌錛屾墍浠ョ幇鍦╳ithout_resource鏄?/p>
"www.webmonkey.com/javascript/index.html."
var second_split = without_resource.split("/");
灝唚ithout_resource鍒嗗壊鎴愶紦鍧楋細(xì)www.webmonkey.com,javascript, 鍜宨ndex.html錛庣幇
鍦ㄤ綘鍙互鐪嬪埌split鐨勭敤閫斾簡鍚э紵
var domain = second_split[0];
鐜板湪鎴戜滑鎻愬彇鍑烘柊鏁扮粍涓殑絎紤涓厓绱犲氨鍙緱鍑哄煙鍚嶏紟
Evaluates an expression after a specified number of milliseconds has elapsed.
(鍦ㄦ寚瀹氭椂闂磋繃鍚庢墽琛屾寚瀹氱殑琛ㄨ揪寮?
Syntax:
Parameters
vCode Required. Variant that specifies the function pointer or string that indicates the code to be executed when the specified interval has elapsed. iMilliSeconds Required. Integer that specifies the number of milliseconds. sLanguage Optional. String that specifies one of the following values:
JScript Language is JScript. VBScript Language is VBScript. JavaScript Language is JavaScript.
Return Value
Integer. Returns an identifier that cancels the evaluation with the clearTimeout method.
==============================================================
浠ヤ笂鍐呭鎽樿嚜鏌愭湰JScript鏁欑▼(CHM鏍煎紡,鍑哄涓嶈,璺熷師浣滆呰澹癝orry)
浠ヤ笅鍐呭娌℃妱浠諱綍浜虹殑,濡傛灉鏈夐浄鍚?浼拌涓嶆槸浣犳妱鍋剁殑灝辨槸宸у悎,鍢垮樋.
-------------------------------------------------------------------
setTimeout( alert("3縐掔榪囧幓浜?), 3000);//璋冪敤涓涓嚱鏁?鍏佽甯﹀父閲忓弬鏁?br /> -------------------------------------------------------------------
<script language="Javascript">
//by zuoyang
var x = 1;
var y = 2;
var z = 3;
var sum;
function Plus(a, b)
{
var z = 0;
var i = 0;
for (i = 0; i < arguments.length; i++)
{
z += arguments[i];
}
setTimeout( function() {alert(z);}, 6000); //鍙互甯﹀彉閲忓弬鏁扮殑setTimeout璋冪敤褰㈠紡
return z;
}
setTimeout( function(){ sum = Plus(x, y, z); }, 3000);/*闄や簡鍙互甯﹀彉閲忓弬鏁拌繕鍙互鑾峰彇榪斿洖鍊肩殑setTimeout璋冪敤褰㈠紡*/
</script>setInterval()鐨勭敤娉曞拰setTimeout()鏄竴鏍風(fēng)殑:
iTimerID = window.setInterval(vCode, iMilliSeconds [, sLanguage])涓嶅悓鐨勬槸setTimeout()鏄竴嬈℃т綔鐢?鑰宻etInterval()鏄瘡闅?em>iMilliSeconds灝辨墽琛屼竴嬈?em>vCode.(Evaluates an expression each time a specified number of milliseconds has elapsed)
鍋囧鏂囨湰涓寘鍚簡澶ч噺鐨?"<" 鍜?"&" 瀛楃 - 灝卞儚緙栫▼浠g爜涓粡甯稿嚭鐜扮殑鎯呭喌涓鏍?- 閭d箞榪欎釜 XML 鍏冪礌灝卞彲浠ヨ瀹氫箟涓轟竴涓?CDATA 閮ㄥ垎銆?/p>
CDATA 鍖烘寮濮嬩簬 "<![CDATA["錛岀粨鏉熶簬 "]]>"錛?/p>
<script type="text/javascript">
<![CDATA[
function compare(a,b)
{
if (a < b)
{alert("a灝忎簬b");}
else if (a>b)
{alert("a澶т簬b");}
else
{alert("a絳変簬b");}
}
]]>
</script>
鍦ㄤ笂闈㈢殑渚嬪瓙涓紝鍦?CDATA 鍖烘涓殑鎵鏈変笢瑗塊兘浼?xì)琚В鏋愬櫒蹇界暐銆?/p>
鍏充簬 CDATA 鍖烘鐨勬敞閲?
CDATA 鍖烘涓嶈兘鍖呭惈瀛楃涓?"]]>"錛屾墍浠ワ紝CDATA 鍖烘鐨勫祵濂楁槸涓嶈鍏佽鐨勩?/p>
鍚屾椂涔熼渶瑕佺‘淇濆湪 "]]>" 瀛楃涓蹭腑娌℃湁絀烘牸鎴栨姌琛屻?/p>
涓轟粈涔堣浣跨敤CDATA:
XHTML鐨勭浜屼釜鏀瑰彉鏄嬌鐢–DATA孌點(diǎn)俋ML涓殑CDATA孌電敤浜庡0鏄庝笉搴旇瑙f瀽涓烘爣絳劇殑鏂囨湰錛圶HTML涔熸槸濡傛錛夛紝榪欐牱灝卞彲浠ヤ嬌鐢ㄧ壒孌婂瓧絎︼紝濡? 灝忎簬錛?lt;錛夈佸ぇ浜庯紙>錛夈佸拰鍙鳳紙&錛夊拰鍙屽紩鍙鳳紙"錛夛紝鑰屼笉蹇呬嬌鐢ㄥ畠浠殑瀛楃瀹炰綋銆傝冭檻涓嬮潰鐨勪唬鐮侊細(xì)
<script type="text/javascript">
function compare(a,b)
{
if (a < b)
{alert("a灝忎簬b");}
else if (a>b)
{alert("a澶т簬b");}
else
{alert("a絳変簬b");}
}
</script>
榪欎釜鍑芥暟鐩稿綋綆鍗曪紝瀹冩瘮杈冩暟瀛梐鍜宐錛岀劧鍚庢樉紺烘秷鎭鏄庡畠浠殑鍏崇郴銆備絾鏄紝鍦╔HTML涓紝榪欐浠g爜鏄棤鏁堢殑錛屽洜涓哄畠浣跨敤浜嗕笁涓壒孌婄鍙鳳紝鍗沖皬浜庛? 澶т簬鍜屽弻寮曞彿銆傝淇榪欎釜闂錛屽繀欏誨垎鍒敤榪欎笁涓瓧絎︾殑XML瀹炰綋<銆?amp;gt;鍜?amp;quot;鏇挎崲瀹冧滑錛?/p>
<script type="text/javascript">
function compare(a,b)
{
if (a <b)
{alert("a灝忎簬b");}
else if (a>b)
{alert("a澶т簬b");}
else
{alert("a絳変簬b");}
}
</script>
榪欐浠g爜瀛樺湪涓や釜闂銆傞鍏堬紝寮鍙戣呬笉涔?fàn)鎯敤XML瀹炰綋緙栧啓浠g爜銆傝繖浣夸唬鐮佸緢闅捐鎳傘傚叾嬈★紝鍦↗avaScript涓紝榪欑浠g爜瀹為檯涓婂皢瑙嗕負(fù)鏈夎娉? 閿欙紝鍥犱負(fù)瑙i噴紼嬪簭涓嶇煡閬揦ML瀹炰綋鐨勬剰鎬濄傜敤CDATA孌靛嵆鍙互浠ュ父瑙勫艦寮忥紙鍗蟲槗璇葷殑璇硶錛夌紪鍐橨avaScript浠g爜銆傛寮忓姞鍏DATA孌電殑鏂規(guī)硶濡? 涓嬶細(xì)
<script type="text/javascript">
<![CDATA[
function compare(a,b)
{
if (a < b)
{alert("a灝忎簬b");}
else if (a>b)
{alert("a澶т簬b");}
else
{alert("a絳変簬b");}
}
]]>
</script>
铏界劧榪欐槸姝e紡鏂瑰紡錛屼絾榪樿璁頒綇錛屽ぇ澶氭暟嫻忚鍣ㄩ兘涓嶅畬鍏ㄦ敮鎸乆HTML錛岃繖灝卞甫鏉ヤ富瑕侀棶棰橈紝鍗寵繖鍦↗avaScript涓槸涓娉曢敊璇紝鍥犱負(fù)澶у鏁版祻瑙堝櫒榪樹笉璁よ瘑CDATA孌點(diǎn)?/p>
<script type="text/javascript">
//<![CDATA[
function compare(a,b)
{
if (a < b)
{alert("a灝忎簬b");}
else if (a>b)
{alert("a澶т簬b");}
else
{alert("a絳変簬b");}
}
//]]>
</script>
褰撳墠浣跨敤鐨勮В鍐蟲柟妗堟ā浠夸簡“瀵規(guī)棫嫻忚鍣ㄩ殣钘?#8221;浠g爜鐨勬柟娉曘備嬌鐢ㄥ崟琛岀殑JavaScript娉ㄩ噴"http://"錛屽彲鍦ㄤ笉褰卞搷浠g爜璇硶鐨勬儏鍐典笅宓屽叆CDATA孌碉細(xì)
鐜板湪錛岃繖孌典唬鐮佸湪涓嶆敮鎸乆HTML鐨勬祻瑙堝櫒涓篃鍙繍琛屻?/p>
浣嗘槸錛屼負(fù)閬垮厤CDATA鐨勯棶棰橈紝鏈濂借繕鏄敤澶栭儴鏂囦歡寮曞叆JavaScript浠g爜銆?/p>
Making JavaScript Compatible with XHTML
XHTML is subject to the same syntactical rules as XML. Because of this, an XHTML processor treats the characters < and & as markup, even if they reside inside a <script> block. Since the < and & characters are also used by the JavaScript language, this creates a conflict. When an XHTML processor sees these characters within the JavaScript code of a <script> block, it attempts to parse the JavaScript code as if it were markup, which causes the XHTML parser to fail.
You can get around this conflict and make all JavaScript code compatible with XHTML by placing the JavaScript code within a CDATA section. A CDATA section in XML/XHTML starts with the characters <![CDATA[ and ends with the characters ]]>.
Any characters within the starting and ending element of a CDATA section are not treated by the XML/XHTML processor as markup, thus preventing a conflict.
Here is an example of how to declare JavaScript code within a CDATA section so that it is compatible with XHTML:
<script type="text/javascript">Note that JavaScript source code must be placed within the opening and closing elements of the CDATA section. The CDATA section itself should be commented out with a JavaScript single-line comment // as in the example above. This is so that the JavaScript interrupter does not interpret the CDATA markup as JavaScript, which would cause a JavaScript error.
JavaScript code that is imported into an XHTML document from an external source file is always compatible with XHTML. So, for example, any code you place into the external file external.js and import into an XHTML file via the src attribute of the <script> tag will be valid. Here is an example of how to import the file external.js:
<script type="text/javascript" src="external.js"></script>XHTML™ 1.0 The Extensible HyperText Markup Language (Second Edition) 瀹氫箟XHTML鏄負(fù)浜嗘妸HTML 4鎵╁睍鎴愬儚XML 1.0涓鏍風(fēng)殑搴旂敤紼嬪簭銆?
鍦ㄨ澶氱珯鐐逛腑XHTML姝e湪榪呴熺殑鏇夸唬HTML 4錛涚劧鑰岋紝涓繪祦嫻忚鍣ㄥ瀹屽叏鏀寔XHTML鏂歸潰琛ㄧ幇寰椾笉瓚籌紝鍜岀綉欏佃璁″笀瀵笻TML 4涓嶺HTML鐨勫熀鏈樊寮傜己涔忕悊瑙o紝浜х敓浜嗗綋浠婄綉緇滀笂鐨勪竴涓笉鏂墿澶х殑闂銆?
鍏朵腑鍏充簬XHTML鐨勪富瑕佺殑璇В鏄紝瀹冧粎浠呮槸鍙﹀涓涓増鏈殑HTML銆傝繖涓瑙d駭鐢熶簬榪欐牱鐨勪簨瀹烇細(xì)Microsoft® Internet Explorer鍙湪鏂囦歡浠ime綾誨瀷涓?text/html鎻愪氦鏃訛紝鎵嶆敮鎸乆HTML錛岃屾爣鍑嗕腑寤鴻鐨勭被鍨嬪叾瀹炴槸application/xhtml+xml銆?
褰撲竴涓猉HTML欏甸潰鐨凪IME綾誨瀷琚彁浜や負(fù)text/html鏃訛紝瀹冭鎵鏈夌殑嫻忚鍣ㄥ綋浣淗TML澶勭悊錛屽氨濂藉儚XHTML姣旇搗HTML鏉ユ病鏈変換浣曚笉鍚屻備絾鏄綋涓涓猉HTML欏甸潰鐨凪IME綾誨瀷琚彁浜や負(fù)text/xml鎴?tt>application/xhtml+xml鏃訛紝瀹冨皢琚綋浣淴ML鏂囨。澶勭悊錛岃岃璁″拰鏄劇ずXML閮芥槸蹇呴』瑕侀伒瀹堜弗鏍艱鍒欑殑銆?
鐪熸鐨刋HTML灝辨槸涓涓猉ML鐨勫簲鐢紝鎵浠ュ垱寤篨HTML鏃朵篃瑕侀伒瀹堜弗鏍肩殑瑙勫垯銆傜壒鍒槸錛?
鍦ㄨ褰撲綔XML鑰屼笉鏄疕TML澶勭悊鏃訛紝鍐呭祵鐨剆tyle鍜宻cript鏍囪浼?xì)漶旂敓鍑犱釜涓嶅悓鐨勯棶棰樸?
鍏稿瀷鐨凧avaScript涓寘鍚簡涓浜涚壒孌婂瓧絎︼紝榪欎簺瀛楃鍦╔HTML涓槸涓嶅厑璁告斁鍦–DATA鍖哄煙涔嬪鐨勩?
<script type="text/javascript">
var i = 0;
while (++i < 10)
{
// ...
}
</script>
娉ㄦ剰榪欎釜渚嬪瓙涓嶆槸浠ユ紜牸寮忎功鍐欑殑XHTML錛屽洜涓轟嬌鐢ㄤ簡鏈粡澶勭悊鐨?#8220;<”錛屽畠鍙兘鍦ㄨ褰撲綔XHTML鎴朮ML鏍囪鐨勪竴閮ㄥ垎鏃跺嚭鐜般?
鐔熸?zhèn)塇TML鐨勮璁″笀閫氬父鎶婂唴宓岀殑style鍜?tt>script鍐呭鏀懼埌娉ㄩ噴涓紝榪欐牱鍙互鍦ㄤ笉鏀寔鏍峰紡鍜岃剼鏈殑嫻忚鍣ㄤ腑闅愯棌瀹冧滑銆?
<style type="text/css">
<!--
body {background-color: blue; color: yellow;}
-->
</style>
<script type="text/javascript">
<!--
var i = 0;
var sum = 0;
for (i = 0; i < 10; ++i)
{
sum += i;
}
alert('sum = ' + sum);
// -->
</script>
榪欎釜渚嬪瓙涓句緥璇存槑浜嗙壒瀹氱殑嫻忚鍣ㄥ彲浠ュ拷鐣ユ敞閲婇噷鐨勫唴瀹廣傚彟澶栵紝榪欎釜渚嬪瓙榪樻樉紺轟簡涓嶅悓鐨勬祻瑙堝櫒鍦ㄥ鐞?tt>text/xml鎴栬?application/xhtml+xml鍐呭鏃朵駭鐢熺殑涓嶅悓闂銆?
鍙︿竴涓妸JavaScript鍖呭惈鍦╔HTML鏂囦歡鐨勬敞閲婁腑浜х敓鐨?a rel="internal" >闂錛屼笌鍦╔HTML鐨勬敞閲婁腑浣跨敤鍙屾í綰夸細(xì)浜х敓鐨勯棶棰樹竴鏍楓?
<script type="text/javascript">
<!--
var i;
var sum = 0;
for (i = 10; i > 0; --i)
{
sum += i;
}
// -->
</script>
鐩存帴鎶奐avaScript鏀懼叆CDATA鍖哄煙浼?xì)鍦ㄤ綆鐗堟湰涓嶆敮鎸乆ML鐨勬祻瑙堝櫒涓駭鐢熼棶棰橈紝涓嶈繃錛屾妸JavaScript鐨勬敞閲?//……)涓嶤DATA涓璧蜂嬌鐢紝灝辮兘瑙e喅鍚戜笅鍏煎鐨勯棶棰樹簡銆?
<script type="text/javascript">
//<![CDATA[
var i = 0;
while (++i < 10)
{
// ...
}
//]]>
</script>
鐢ㄥ閮ㄦ枃浠跺寘鍚獵SS瑙勫垯鍜孞avaScript鏉ユ浛鎹㈠唴鑱旀牱寮忓拰鑴氭湰鏄垱寤篨HTML鏈浣蟲柟寮忥紝鍦ㄥ悜鍚庡吋瀹規(guī)柟寮忔椂錛屽鏋滃唴瀹圭殑MIME綾誨瀷浠?tt>text/html鍚?tt>application/xhtml+xml鏀瑰彉鏃跺皢涓嶄細(xì)琚墦鏂?
榪欎釜寤鴻鍙兘鐪嬭搗鏉ユ洿寮虹儓錛屽彲鏄紝瀹冩槸鏈潵XHTML瑕佹墦綆楃殑闂錛屽綋XHTML鍦?tt>text/html鍚?tt>application/xhtml+xml杞Щ鍦ㄥ嚑騫村悗鍙戠敓銆?
濡傛灉浣犱粎浠呮祴璇曚綘鐨刋HTML鍦?tt>text/html鐨勬椂鍊欙紝閭d箞浣犲彲鑳戒駭鐢熼棶棰橈紝渚嬪鍍忥細(xì)涓嶈兘鍑嗙‘鐨勬弿榪板嚭涓婚銆傜Щ鍔–SS鍜孞avaScript鍒板崟鐙殑鏂囦歡鏄彲闈犵殑鏂規(guī)硶錛屽叧浜庢敼鍙樹綘XHTML鐨勬湇鍔℃柟寮忋?
榪欎釜XHTML 1.0 HTML Compatibility Guidelines甯姪鍒涘緩XHTML鏂囨。鍚戝悗鍏煎鎬у湪閭d簺涓嶈兘鐞嗚ВXML鐨勮佹祻瑙堝櫒銆?
璇鋒敞鎰忛偅鏄函綺圭殑XHTML鏂囨。錛屼綘涓嶉渶瑕佷嬌鐢▁ml-stylesheet澶勭悊鎸囧錛屼絾搴旇浣跨敤link娑夊強(qiáng)鐨勫閮ㄦ枃浠跺寘鍚獵SS銆?
鏈枃杞嚜錛?/span>http://info.codepub.com/2008/09/info-22582.html
鍘熸枃濡備笅錛?/span>
鍔熻兘涓嶆槸寰堝錛屼絾寰堣交閲忥紝寰堢伒媧匯傛墦鍖呭悗鍙湁6.5K澶у皬銆?/p>
闈炲父鍩烘湰鐨勭紪杈戝櫒錛岀畝鍗曚負(fù)鏈傛墦鍖呭悗鍙湁7K銆?/p>
綆鍗曞埌涓嶈兘鍐嶇畝鍗曪紝寰堝鏄撹嚜宸變慨鏀廣?/p>
璺ㄦ祻瑙堝櫒錛屽紑婧愶紝鍩轟簬 jQuery銆傚彲浠ュ緢瀹規(guī)槗鍚屽悇縐?CMS錛岃鍧涳紝鐣欒█鏈紝鍗氬絳夌郴緇熼泦鎴愩?/p>
鍩轟簬 iframe 瀵硅薄銆?/p>
鏈緇忓吀鐨勫熀浜?JavaScript 鐨勭紪杈戝櫒錛孋OMSHARP CMS 榛樿鐨勭紪杈戝櫒灝辨槸榪欎釜銆?/p>
鍔熻兘闈炲父寮哄ぇ銆?/p>
鍩轟簬 Yahoo YUI錛岀畝鍗曪紝浣嗗緢鍙潬銆?/p>
鑷敱鐨勫熀浜?nbsp; BSD 璁稿彲緙栬緫鍣紝鍔熻兘瀹屽杽錛屽緢閫傚悎鍚屽悇縐嶇郴緇熼泦鎴愩?/p>
鏈枃鍘熸枃鏉ユ簮錛?a >http://www.queness.com/post/212/10-jquery-and-non-jquery-javascript-rich-text-editors
The Pop-up Blocking feature blocks pop-up (and pop-under) windows initiated automatically by a Web site. Internet Explorer blocks Pop-up windows in the Internet and Restricted sites zones by default. However, the Pop-up Blocker enables pop-up windows initiated by a user action. Users can configure Internet Explorer 6 for Windows XP with SP2 to be more or less restrictive. Users can also turn off the Pop-up Blocker altogether. Generally, the Pop-up Blocker enables a window to open under the following circumstances:
• |
When initiated by user action, such as clicking a button or hyperlink |
• |
When opened in the Trusted sites and Local intranet zones (considered safe) |
• |
When opened by other applications running on the local computer |
The affected script methods are:
window.open
window.showHelp
window.showModalDialog
window.showModelessDialog
window.external
window.NavigateAndFind
|
|
Pop-ups created with window.createPopup are unaffected by the Pop-up Blocker. |
鍦╳eb緙栫▼榪囩▼涓紝緇忓父浼?xì)閬囧堫C竴浜涢〉闈㈤渶瑕佸脊鍑虹獥鍙o紝浣嗘槸鍦ㄦ湇鍔″櫒绔敤window.open寮瑰嚭鐨勭獥鍙d細(xì)琚獻(xiàn)E闃繪鎺夛紝showModalDialog寮瑰嚭鐨勭獥鍙f湁鏃跺茍涓嶈兘婊¤凍鎴戜滑闇瑕侊紝鎴戜滑闇瑕佸脊鍑烘柊鐨勬祻瑙堝櫒紿楀彛銆?/p>
涓轟粈涔堟垜浠紪鍐欑殑寮瑰嚭紿楀彛浼?xì)琚獻(xiàn)E闃繪鍛紝鍘熸潵IE浼?xì)鑷姩鍒ゆ柇寮瑰嚭绐楀彛鐨勭姸鎬侊紝瀹冧細(xì)闃繪鑷姩寮瑰嚭鐨勭獥鍙o紝鑰岄氳繃鎴戜滑鐢ㄩ紶鏍囩偣鍑誨脊鍑虹殑紿楀彛錛屽畠鏄笉浼?xì)闃绘鐨勩傝繖閲屽氨鏈変竴涓棶棰橈紝鏈変漢璇達(dá)細(xì)鎴戠殑紼嬪簭鏄啓鍦ㄦ湇鍔″櫒鎸夐挳閲岀殑錛屼篃鏄氳繃榧犳爣鐐瑰嚮寮瑰嚭鐨勫憖錛佸叾瀹炲彧鏈夊湪鍔犺澆欏甸潰鍚庯紝鎴戜滑鐐瑰嚮鍒板脊鍑鴻繖孌墊椂闂撮〉闈㈡病鏈夎閲嶆柊鍔犺澆鐨勬儏鍐典笅錛屽脊鍑虹殑紿楀彛鎵嶄笉浼?xì)琚樌L錛佽繖涔熷氨鏄錛屽啓鍦ㄦ湇鍔″櫒鎺т歡鐨勫洖浼犱簨浠墮噷鐨剋indow.open閮戒細(xì)琚樆姝€?br />
緇х畫Google瑙e喅鍔炴硶錛屽湪鍒嗘瀽浜嗗嚑縐嶈В鍐蟲柟娉曞茍榪涜瀵規(guī)瘮涔嬪悗錛屽彂鐜版渶綆鍗曟湁鏁堢殑鏂規(guī)硶濡備笅錛?br />
鍦╳indow.open()鍑芥暟涓鍔犱竴涓弬鏁幫紝灝唗arget璁劇疆涓?#8216;self’錛?br />
鍗蟲敼涓轟嬌鐢細(xì) window.open(link,'_self');
闂瑙e喅銆?/p>