??xml version="1.0" encoding="utf-8" standalone="yes"?>
* @param obj 要处理的控g, 支持文本域和输入?br />
* @author
hotleave
*/
提示Q?zhn)?
可以先修攚w分代码再q行
提示Q?zhn)?
可以先修攚w分代码再q行
]]>
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.
后来扑ֈ国外的一帖子,扑ֈ一个解x法,那就是?a title="MSDN mergeAttributes Documentation" >mergeAttributes Ҏ(gu)Q模拟新Z个只有name不同的元素,q和之前的元素合qӞq样p辑ֈ重命名的效果了。代码如下:(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> | cd | Default | 描述 | ||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
method | Array | 'post' | HTTP h方式。get or post | ||||||||||||||||||||||||||||||||||||||||||||||
parameters | String | '' | 在HTTPh中传入的url格式的值列表?/td> | ||||||||||||||||||||||||||||||||||||||||||||||
asynchronous | Boolean | true | 指定是否做异?AJAX h?/td> | ||||||||||||||||||||||||||||||||||||||||||||||
postBody | String | undefined | 在HTTP POST的情况下Q传入请求体中的内容?/td> | ||||||||||||||||||||||||||||||||||||||||||||||
requestHeaders | Array | undefined | 和请求一赯传入的HTTP头部列表Q?q个列表必须含有偶数个项目, M奇数目是自定义的头部的名称Q? 接下来的偶数目使这个头部项目的字符串倹{?例子:['my-header1', 'this is the value', 'my-other-header', 'another value'] | ||||||||||||||||||||||||||||||||||||||||||||||
onXXXXXXXX | Function(XMLHttpRequest) | undefined | 在AJAXh中,当相应的事g/状态Ş成的时候调用的自定义方法?例如 var myOpts = {onComplete: showResponse, onLoaded: registerLoaded};. q个Ҏ(gu)被传入一个参敎ͼ q个参数是携带AJAX操作?XMLHttpRequest对象?/td> | ||||||||||||||||||||||||||||||||||||||||||||||
onSuccess | Function(XMLHttpRequest) | undefined | 当AJAXh成功完成的时候调用的自定义方法?q个Ҏ(gu)被传入一个参敎ͼ q个参数是携带AJAX操作?XMLHttpRequest对象?/td> | ||||||||||||||||||||||||||||||||||||||||||||||
onFailure | Function(XMLHttpRequest) | undefined | 当AJAXh完成但出现错误的时候调用的自定义方法?q个Ҏ(gu)被传入一个参敎ͼ q个参数是携带AJAX操作?XMLHttpRequest对象?/td> | ||||||||||||||||||||||||||||||||||||||||||||||
insertion | Function(Object, String) | null | Z把返回的文本注入C个元素中而执行的Ҏ(gu)?q个Ҏ(gu)被传入两个参数Q要被更新的对象q且只应用于 Ajax.Updater 对象中应用?/td> | ||||||||||||||||||||||||||||||||||||||||||||||
decay | Number | undefined, 1 | 军_当最后一ơ响应和前一ơ响应相同时?function getContents() { var request_url = "test1.html"; // 需要获取内容的url var request_pars = '';//h参数 var myAjax = new Ajax.Updater('result', request_url,{ // request_urlq回内容l定到id为result的容器中 method : 'get', //HTTPh的方?get or post parameters : request_pars, //h参数 onFailure : reportError, //p|的时候调?nbsp;reportError 函数 onLoading : loading, //正在获得内容的时?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 为我们提供加载文档时候的三种状? onComplete,onLoading,onFailure.我们可以自定义一个函数分别相应这三种不同的状态?br /> 下面的例子用Csuccess (一切OK的时候才被用? Q和它同{地位的属性还有一?font face="Courier New">failure (有地方出问题的时候被用到) q里没用到。出错时?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个优U的jQuery囄qȝ?d效果Q基本都已经包含了原插g的发布地址、用方法和源代码下载?/p>
Galleriffic 是? Mike Alsup ?jQuery Cycle plugin 创徏的图片展C效果,包括~略图、图片标题和描述{详l功能,是一个非怸错的高质量画廊相册展C工兗?/p>
zoomimage Q以一U独具魅力的方式展示囄效果。羃略图链接在本弹出大图,q且可以可以随意拖拽该?zhn)图片?/p>
Easy Slider 可以实现囄或其他Q意内容,在水qx垂直方向上的滑动效果Q你q可以通过 CSS 自定义设|样式?/p>
一个源自美国ȝ Barack Obama |站的垂下滑动菜单控制的囄qȝ效果?/p>
CodaSliderQ? 又一个不错的滑动控制效果?/p>
jQuery Slider II 的布局非常W合操作?fn)惯Q在底部列出带滚动条的羃略图控制列表Q然后在上面昄对应囄的大图浏览,非常适合做高U相册?/p>
Beautiful SliderQ? 光看q个效果图你q道这个插件有多棒了吧Q是的,q个插g实现的效果已l不逊色于Flash完成的效果,整体表现畅Q文字显C效果更是创意独牏V?/p>
loopedSlider是又一个Q意内Ҏ(gu)? 切换的灯片插gQ用操作简单?/p>
SpaceGallery是一个全新的jQuery插gQ点d 前图片,?x)自动放大消失,同时后面的图片向前展C,有一U时光机器的感觉?/p>
SmoothGallery是一个最好的 Javascript qȝ片效果之一Q可以实现各U不同的qȝ片{换效果?/p>
jQuery Multimedia Portfolio是一个基于jQuery 的滑动效果插?除了可以展示囄之外Q还可以加入各种不同cd的多媒体文g?/p>
s3Slider是一个非常简单实用的畅qȝ片效果,q个
插g被应用在无数的WordPress专业主题模板中?/p>
javascript 字符串处?/strong>
文章来源Q?a target="_blank">http://lmgq.vip.sina.com/tech/jsadvancedlesson/c2p1.htm
一、声明字W串:
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);
q里的声明:(x) var bold_monkey = normal_monkey.bold();
和下面对声明是等同的Q?nbsp;
var bold_monkey = "<b>" + normal_monkey + "</b>";
W?个版本的声明看v来要明得多。这里用C字符串对象中
的bold对象Q其他的字符串对象还有indexOf, charAt,
substring, 以及(qing)split, q些Ҏ(gu)可以深入字符串的l成l构?br />
首先我们研究一下indexOf?/p>
2、indexOf
indexOf用于发现一pd的字W在一个字W串中等位置q告诉你子字W串的v始位|。如
果一个字W串中部包含该子字符串则indexOfq回returns "-1."
例子Q?br />
var the_word = "monkey";
//让我们从单词 "monkey"开始?nbsp;
var location_of_m = the_word.indexOf("m");
//location_of_m(字母m的位|?ؓ(f)0Q因为字母m位于该字W串的v始位|?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)子字W串“key”以字母k开始,而k
在单词monkey中的位置??br />
var location_of_y = the_word.indexOf("y");
//location_of_y)字母y的位|???nbsp;
var cheeky = the_word.indexOf("q");
//cheeky值是-1Q因为在单词“monkey”中没有字母q?/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.");
}
q段代码询问用户的电(sh)子邮件地址Q如果用戯入的?sh)子邮g地址中不包含字符 ?nbsp;?/p>
C用PQ你输入的电(sh)子邮件地址无效Q电(sh)子邮件的地址必须包含字符@。"
3、charAt
chatAtҎ(gu)用于发现一个字W串中某个特定位|的字符?br />
q里是一个例子:(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(W?个字W??m"
the_second_letter(W?个字W??o"
the_last_letter(最后一个字W??nbsp;"y"
注意利用字符串的length(长度)属性你可以发现在包含多个字符。在本例中,
the_word?monkey"Q所以the_word.length?。不要忘记在一个字W串中第1个字W的
位置?Q所以最后一个字W的位置是length-1。所以在最后一行中用了
the_word.length-1?gt;>
4、子字符ԌsubstringQ?br /> 子字W串QsubstringQ和charAt有些象,不同之处在于它能够从一个单词中抓取整个?/p>
子字W串Q而不只是字母Q这里是其格式:(x)
var the_substring = the_string.substring(from, to);
"From"指的是子字符串中W1个字母的位置Q?to"有点奇特Q它是该子字W串中比最?/p>
一个位|大Q的位置Q用这U神奇的Ҏ(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);
q行该段代码后变量clergy的gؓ(f)"monk"; 变量tool的gؓ(f)"key"?/p>
子字W串常和indexOf一起用,字W串分成若干块.例如Q?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);
q段代码的意思是Q如果你输入
"http://www.webmonkey.com/javascript/index.html";Q则域名
是
"www.webmonkey.com" Q如果这个方法对你来说有些麻烦,我将向你介绍如何使用split
Ҏ(gu)化其执行q程Q但是首先我们作一些分析.
基本的技巧是第Q个斜杠和第Q个斜杠之间的内容分d来:(x)
var the_url = prompt("What’s the URL?","");
//q行代码向用戯问一个URLQ假讄戯入了
"http://www.webmonkey.com/javascript/index.html.";
var lead_slashes = the_url.indexOf("http://");
q行代码定W一个双斜杠的位|.在本例中lead_slashes的值是Q,因ؓ(f)双斜杠的?/p>
|从Q开始.
你可能会(x)惻I通常的URL都是以http://开始,所以双斜杠的位|肯定是在5开始,Z
么还要加入indexOfq一D多余的代码呢?但是问题的关键在于你不知道用户在填入URL
时是否一定填入http:Q他们也怼(x)不小心多键入了一个空|也许他们所键入的URL?/p>
一个加密服务器上,其URL?https://www.whatever.com/"; Q? 在编E你必须预料到种U?/p>
可能发生的问题.所以我们必ȝindexOfҎ(gu)定双斜杠的切的v始位|.
var domain_start = lead_slashes + 2;
q行代码用于计算该域名的W1个字母的起始位置Q由于这里有一个双斜杠Q所以域?/p>
W1个字母的起始位置应该在双斜杠所在位|加Q的位置Q?/p>
var without_resource = the_url.substring(domain_start, the_string.length);
q段代码域名v始位|往后的所有字W都提取出来Q所以执行完q行代码?/p>
without_resource?www.webmonkey.com/javascript/index.html."
var next_slash = without_resource.indexOf("/");
q行代码计算字符串中下一个斜杠的位置Q而从该字W串起始位置到这个斜杠之?/p>
的内容就是域名.在本例中下一个斜杠的位置?7?/p>
var domain = without_resource.substring(0, next_slash);
最后一步是提取字符串v始位|到下一个斜杠之间的所有内容.在本例中使得域名
{同?www.webmonkey.com"?/p>
q样做确实很ȝQ利用splitҎ(gu)则可以该过E容易很多.>>
5、分割方?splitting method)
你可以用splitҎ(gu)用限位器来分割一pd的名Uͼ然后其
攑֜一个数l中Q例如:(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>");}
q段代码字W串my_friends分割成包含5个元素的数组QJavaScript可以Z自动?/p>
立一个数l,所以你无需使用new Array()Q?/p>
字W串分割成数l之后,我们使用了@环语句写出每一个名Uͼ我们可以利用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];
q段代码化了很多而且也更Ҏ(gu)理解Q我们来分析一些这D代码:(x)
var the_url = prompt("What’s the URL?","");
提示用户输入一个URLQ假讄戯?br />
"http://www.webmonkey.com/javascript/index.html"; Q?br />
var first_split = the_url.split("http://");
用戯入的字符串分割成两块Qfirst_split[0]?http:"Qfirst_split[1]?/p>
"www.webmonkey.com/javascript/index.html."
var without_resource = first_split[1];
//提取出数l中的第Q个元素Q所以现在without_resource?/p>
"www.webmonkey.com/javascript/index.html."
var second_split = without_resource.split("/");
without_resource分割成3块:(x)www.webmonkey.com,javascript, 和index.htmlQ现
在你可以看到split的用途了吧?
var domain = second_split[0];
现在我们提取出新数组中的W1个元素就可得出域名.
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格式,出处不详,跟原作者说声Sorry)
以下内容没抄M人的,如果有雷?估计不是你抄偶的是巧合,嘿嘿.
-------------------------------------------------------------------
setTimeout( alert("3U种q去?), 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);/*除了可以带变量参数还可以获取q回值的setTimeout调用形式*/
</script>setInterval()的用法和setTimeout()是一L(fng):
iTimerID = window.setInterval(vCode, iMilliSeconds [, sLanguage])不同的是setTimeout()是一ơ性作?而setInterval()是每?em>iMilliSeconds执行一?em>vCode.(Evaluates an expression each time a specified number of milliseconds has elapsed)
假如文本中包含了大量?"<" ?"&" 字符 - 像~程代码中经常出现的情况一?- 那么q个 XML 元素可以被定义Z?CDATA 部分?/p>
CDATA 区段开始于 "<![CDATA["Q结束于 "]]>"Q?/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 区段中的所有东襉K?x)被解析器忽略?/p>
关于 CDATA 区段的注?
CDATA 区段不能包含字符?"]]>"Q所以,CDATA 区段的嵌套是不被允许的?/p>
同时也需要确保在 "]]>" 字符串中没有I格或折行?/p>
Z么要使用CDATA:
XHTML的第二个改变是用CDATADc(din)XML中的CDATAD는于声明不应被解析为标{文本QXHTML也是如此Q,q样可以用特D字W,? 于Q?lt;Q、大于(>Q、和P&Q和双引P"Q,而不必用它们的字符实体。考虑下面的代码:(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>
q个函数相当单,它比较数字a和bQ然后显C消息说明它们的关系。但是,在XHTML中,q段代码是无效的Q因为它使用了三个特D符P卛_于? 大于和双引号。要修正q个问题Q必d别用q三个字W的XML实体<?amp;gt;?amp;quot;替换它们Q?/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>
q段代码存在两个问题。首先,开发者不?fn)惯用XML实体~写代码。这使代码很难读懂。其ơ,在JavaScript中,q种代码实际上将视ؓ(f)有语? 错,因ؓ(f)解释E序不知道XML实体的意思。用CDATAD即可以以常规Ş式(xȝ语法Q编写JavaScript代码。正式加入CDATAD늚Ҏ(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>
虽然q是正式方式Q但q要CQ大多数览器都不完全支持XHTMLQ这带来主要问题,卌在JavaScript中是个语法错误,因ؓ(f)大多数浏览器q不认识CDATADc(din)?/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>
当前使用的解x案模仿了“Ҏ(gu)览器隐?#8221;代码的方法。用单行的JavaScript注释"http://"Q可在不影响代码语法的情况下嵌入CDATAD:(x)
现在Q这D代码在不支持XHTML的浏览器中也可运行?/p>
但是Qؓ(f)避免CDATA的问题,最好还是用外部文g引入JavaScript代码?/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一L(fng)应用E序?
在许多站点中XHTML正在q速的替代HTML 4Q然而,L览器对完全支持XHTML斚w表现得不I和网设计师对HTML 4与XHTML的基本差异缺乏理解,产生了当今网l上的一个不断扩大的问题?
其中关于XHTML的主要的误解是,它仅仅是另外一个版本的HTML。这个误解生于q样的事实:(x)Microsoft® Internet Explorer只在文g以Mimecd?text/html提交Ӟ才支持XHTMLQ而标准中的类型其实是application/xhtml+xml?
当一个XHTML面的MIMEcd被提交ؓ(f)text/htmlӞ它被所有的览器当作HTML处理Q就好像XHTML比vHTML来没有Q何不同。但是当一个XHTML面的MIMEcd被提交ؓ(f)text/xml?tt>application/xhtml+xmlӞ它将被当作XML文档处理Q而设计和昄XML都是必须要遵守严D则的?
真正的XHTML是一个XML的应用,所以创建XHTML时也要遵守严格的规则。特别是Q?
在被当作XML而不是HTML处理Ӟ内嵌的style和script标记?x)生几个不同的问题?
典型的JavaScript中包含了一些特D字W,q些字符在XHTML中是不允许放在CDATA区域之外的?
<script type="text/javascript">
var i = 0;
while (++i < 10)
{
// ...
}
</script>
注意q个例子不是以正格式书写的XHTMLQ因Z用了未经处理?#8220;<”Q它只能在被当作XHTML或XML标记的一部分时出现?
熟?zhn)HTML的设计师通常把内嵌的style?tt>script内容攑ֈ注释中,q样可以在不支持样式和脚本的览器中隐藏它们?
<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>
q个例子举例说明了特定的览器可以忽略注释里的内宏V另外,q个例子q显CZ不同的浏览器在处?tt>text/xml或?application/xhtml+xml内容时生的不同问题?
另一个把JavaScript包含在XHTML文g的注释中产生?a rel="internal" >问题Q与在XHTML的注释中使用双横U会(x)产生的问题一栗?
<script type="text/javascript">
<!--
var i;
var sum = 0;
for (i = 10; i > 0; --i)
{
sum += i;
}
// -->
</script>
直接把JavaScript攑օCDATA区域?x)在低版本不支持XML的浏览器中生问题,不过Q把JavaScript的注?//……)与CDATA一起用,p解决向下兼容的问题了?
<script type="text/javascript">
//<![CDATA[
var i = 0;
while (++i < 10)
{
// ...
}
//]]>
</script>
用外部文件包含CSS规则和JavaScript来替换内联样式和脚本是创建XHTML最x式,在向后兼Ҏ(gu)式时Q如果内容的MIMEcd?tt>text/html?tt>application/xhtml+xml改变时将不会(x)被打断?
q个可能看v来更强烈Q可是,它是未来XHTML要打的问题Q当XHTML?tt>text/html?tt>application/xhtml+xml转移在几q后发生?
如果你仅仅测试你的XHTML?tt>text/html的时候,那么你可能生问题,例如像:(x)不能准确的描q出主题。移动CSS和JavaScript到单独的文g是可靠的Ҏ(gu)Q关于改变你XHTML的服务方式?
q个XHTML 1.0 HTML Compatibility Guidelines帮助创徏XHTML文档向后兼容性在那些不能理解XML的老浏览器?
h意那是纯_的XHTML文档Q你不需要用xml-stylesheet处理指导Q但应该使用link涉及(qing)的外部文件包含CSS?
本文转自Q?/span>http://info.codepub.com/2008/09/info-22582.html
原文如下Q?/span>
功能不是很多Q但很轻量,很灵zR打包后只有6.5K大小?/p>
非常基本的编辑器Q简单ؓ(f)本。打包后只有7K?/p>
单到不能再简单,很容易自׃攏V?/p>
跨浏览器Q开源,Z jQuery。可以很Ҏ(gu)同各U?CMSQ论坛,留言本,博客{系l集成?/p>
Z iframe 对象?/p>
最l典的基?JavaScript 的编辑器QCOMSHARP CMS 默认的编辑器是q个?/p>
功能非常强大?/p>
Z Yahoo YUIQ简单,但很可靠?/p>
自由的基?nbsp; BSD 许可~辑器,功能完善Q很适合同各U系l集成?/p>
本文原文来源Q?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. |
在web~程q程中,l常?x)遇C些页面需要弹出窗口,但是在服务器端用window.open弹出的窗口会(x)被I(xin)EL掉,showModalDialog弹出的窗口有时ƈ不能满我们需要,我们需要弹出新的浏览器H口?/p>
Z么我们编写的弹出H口?x)被I(xin)EL呢,原来IE?x)自动判断弹出窗口的状态,它会(x)L自动弹出的窗口,而通过我们用鼠标点d出的H口Q它是不?x)阻止的。这里就有一个问题,有h_(d)(x)我的E序是写在服务器按钮里的Q也是通过鼠标点击弹出的呀Q其实只有在加蝲面后,我们点击到弹D|间页面没有被重新加蝲的情况下Q弹出的H口才不?x)被LQ这也就是说Q写在服务器控g的回传事仉的window.open都会(x)被阻止?br />
l箋Google解决办法Q在分析了几U解x法ƈq行Ҏ(gu)之后Q发现最单有效的Ҏ(gu)如下Q?br />
在window.open()函数中增加一个参敎ͼtarget讄?#8216;self’Q?br />
xZ用:(x) window.open(link,'_self');
问题解决?/p>