String.prototype.Trim=function(){
returnthis.replace(/(^\s*)|(\s*$)/g,"");
}
String.prototype.LTrim=function(){
returnthis.replace(/(^\s*)/g,"");
}
String.prototype.RTrim=function(){
returnthis.replace(/(\s*$)/g,"");
} ......
function checkImgAddr(url){
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("post",url,false);
xmlhttp.send();
if(xmlhttp.readyState==4){
if(xmlhttp.status==404){
return "File Not Exist.";
}else if(xmlhttp.status == 200){
return "File is Exist.";
}else{
return xmlhttp.status;
}
}
} ......
//获取页面数据
function getPageSize(){
var xScroll, yScroll;
if (window.innerHeight && window.scrollMaxY) {
xScroll = document.body.scrollWidth;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else{ // Explorer Macwould also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var windowWidth, windowHeight;
if (self.innerHeight) { // all except Explorer
windowWidth = self.innerWidth;
&nb ......
function QueryString(fieldName){
var urlString = location.search;
if (urlString != null) {
var typeQu = fieldName + "=";
var urlEnd = urlString.indexOf(typeQu);
if (urlEnd != -1) {
var paramsUrl = urlString.substring(urlEnd + typeQu.length);
var isEnd = paramsUrl.indexOf('&');
if (isEnd != -1) {
return paramsUrl.substring(0, isEnd);
}
else {
return paramsUrl;
}
}
return null;
}
} ......
JavaScript方法和技巧大全
1:基础知识
1 创建脚本块
1: <script language=”JavaScript”>
2: JavaScript code goes here
3: </script>
2 隐藏脚本代码
1: <script language=”JavaScript”>
2: <!--
3: document.write(“Hello”);
4: // -->
5: </script>
在不支持JavaScript的浏览器中将不执行相关代码
3 浏览器不支持的时候显示
1: <noscript>
2: Hello to the non-JavaScript browser.
3: </noscript>
4 链接外部脚本文件
1: <script language=”JavaScript” src="/”filename.js"”></script>
5 注释脚本
1: // This is a comment
2: document.write(“Hello”); // This is a comment
3: /*
4: All of this
5: is a comment
6: */
6 输出到浏览器
1: document.write(“<strong>Hello</strong>”);
7 定义变量
1: var myVariable = “some value”;
8 字符串相加
1: var myString = “String1& ......
<script >
function showimage()
{
//IMG1为图片控件或Div,File1为上传文件控件
document.getElementById("IMG1"). src = document.getElementById("File1").value;
}
</script >
控件中引用:
<input id="File1" runat="server" type="file" onchange="showimage()"/>
IE7.0中由于不支持绝对路径,会出现图片显示错误.解决办法:
<script >
function showimage()
{
document.getElementById("IMG1").filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src =
document.getElementById ("File1").value;
}
</script >
控件中引用:
<input id="File1" runat="server" type="file" onchange="showimage()"/>
另外需在IMG或DIV样式中修改:
<div id="IMG1" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);width:400px;height:200px;" runat="server" src="" ......