随笔-8  评论-10  文章-5  trackbacks-0
  2008年9月26日

      Javascript以前用过但没有真正从头好好地学习过,前两天拿到了《Javascript高级程序设计》这本书,感觉很好。Javascript相信都被园友们写烂了,我这写下来只是个人学习以备后用。
      一、转换
          A、转换成字符串
                     .toString()。其中Number类型的.toString()比较特殊,其他的就.toString()就好了。
                     Number.toString()有两种模式,即默认模式和基模式。默认模式中,无论整数、浮点数还是科学计数法都是用相应的字符串输出数字值,输
                出的都是数字的十进制。在基模式中,形式为:.toString(parameter)。基模式可以根据基输出不同进制的数。
                如:

Code


          B、转换成数字(只针对String类型)
                  
ECMAScript提供了两种把非数字的原始值转换成数字的方法(parseInt()parseFloat()),方法名已经告诉了我们前一方法转成整数,后一
               方法转成浮点数。应用这两种方法时,方法会先从位置0开始依次判断该位置字符是否为数字,若不是则返回NaN,否则返回相应的数字。
               如:

              

Code

               另外parseInt()方法也和toString()方法一样有基模式,可以返回相应进制的数字
      二、引用类型
          
A、Number类
              
 Number类除了具有Object类的所有方法和属性外还有几个处理数值的专用方法:
                1、toFixed() 返回具有指定位数小数的字符串形式。

Code

                2、toExponential() 返回科学计数法表示的数字的字符串形式.

Code

          B、String类
               String类有大量的处理字符串的方法。
               1、charAt(index)和charCodeAt(index)
                    charAt(index)返回String中的index位置的单个字符,而charCodeAt(index)返回的是字符代码。
               2、concat()连接字符串
                    作用和“+”一样,会保持原始String对象的不变。
               3、localeCompare()
                    按照字母排序顺序对字符串值经行排序,将返回1、0、-1。

Code

               4、截取字符串slice()和substirng()
                   两个方法在传入的参数是正数时候得到结果是一样的,差别就在参数为负数时候。在参数为负数时,slice()方法会用字符串的长度加上参数而
                   substring()方法则是将其作为0处理。

Code

         好了,今天就写到这了,还有些基础的就不写了,明天在往后学习。

posted @ 2008-09-26 14:22 蓝色海岸线 阅读(93) 评论(0) 编辑
  2008年9月11日

很郁闷,今天刚装了下VS08,打开了下以前VS05下的程序,竟然会这样,郁闷。


 不知道为撒?不止这两个控件是这样的,其他控件也一样不能正常显示出来,但是F5运行的话却是Ok的,但是设计时候看这样子很不爽啊,园子里有没有人遇到这种情况啊?怎么解决的啊?我电脑上VS08和VS05都装了,.Net Framework3.5是跟着VS08一起装上去的。各位兄弟帮帮忙啊。

 

 

 

posted @ 2008-09-11 16:42 蓝色海岸线 阅读(341) 评论(7) 编辑
  2008年8月7日
                string strFile = Server.MapPath("../UpLoad/IssueTrackingFiles/")+lbFileList.Items[item].Text;
                System.IO.FileInfo file = new System.IO.FileInfo(strFile);
                Response.Clear();
                Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(file.Name));
                Response.AddHeader("Content-Length", file.Length.ToString());
                Response.ContentType = "application/octet-stream";
                Response.WriteFile(file.FullName);
                Response.End();
posted @ 2008-08-07 13:17 蓝色海岸线 阅读(17) 评论(0) 编辑
  2008年8月1日

方案1:

/// <summary>
/// 传入URL返回网页的html代码
/// </summary>
/// <param name="Url">URL</param>
/// <returns></returns>
public static  string getUrltoHtml(string Url)
{
errorMsg 
= "";
try
{
System.Net.WebRequest wReq 
= System.Net.WebRequest.Create(Url);
// Get the response instance.
System.Net.WebResponse wResp =wReq.GetResponse();
// Read an HTTP-specific property
//if (wResp.GetType() ==HttpWebResponse)
//{
//DateTime updated  =((System.Net.HttpWebResponse)wResp).LastModified;
//}
// Get the response stream.
System.IO.Stream respStream  = wResp.GetResponseStream();
// Dim reader As StreamReader = New StreamReader(respStream)
System.IO.StreamReader reader = new System.IO.StreamReader(respStream, System.Text.Encoding.GetEncoding("gb2312"));
return  reader.ReadToEnd();

}
catch(System.Exception ex)
{
errorMsg 
= ex.Message ;
}
return "";
}

你可以用这个函数获取网页的客户端的html代码,然后保存到.html文件里就可以了。

方案2:

生成单个的静态页面不是难点,难的是各个静态页面间的关联和链接如何保持完整;特别是在页面频繁更新、修改、或删除的情况下;

像阿里巴巴的页面也全部是html的,估计用的是地址映射的功能关于地址映射可参考:http://www.easewe.com/Article/ShowArticle.aspx?article=131

可以看看这个页面,分析一下他的“竞价倒计时”功能http://info.china.alibaba.com/news/subject/v1-s5011580.html?head=top4&Bidding=home5

ASP.Net生成静态HTML页
在Asp中实现的生成静态页用到的FileSystemObject对象!
在.Net中涉及此类操作的是System.IO
以下是程序代码 注:此代码非原创!参考别人代码

//生成HTML页
  public static bool WriteFile(string strText,string strContent,string strAuthor)
  {
   
string path = HttpContext.Current.Server.MapPath("/news/");
   Encoding code 
= Encoding.GetEncoding("gb2312");
   
// 读取模板文件
   string temp = HttpContext.Current.Server.MapPath("/news/text.html");
   StreamReader sr
=null;
   StreamWriter sw
=null;
   
string str=""
   
try
   {
    sr 
= new StreamReader(temp, code);
    str 
= sr.ReadToEnd(); // 读取文件
   }
   
catch(Exception exp)
   {
    HttpContext.Current.Response.Write(exp.Message);
    HttpContext.Current.Response.End();
    sr.Close();
   }
   
string htmlfilename=DateTime.Now.ToString("yyyyMMddHHmmss")+".html";
   
// 替换内容
   
// 这时,模板文件已经读入到名称为str的变量中了
   str =str.Replace("ShowArticle",strText); //模板页中的ShowArticle
   str = str.Replace("biaoti",strText);
   str 
= str.Replace("content",strContent);
   str 
= str.Replace("author",strAuthor);
   
// 写文件
   try
   {
    sw 
= new StreamWriter(path + htmlfilename , false, code);
    sw.Write(str);
    sw.Flush();
   }
   
catch(Exception ex)
   {
    HttpContext.Current.Response.Write(ex.Message);
    HttpContext.Current.Response.End();
   }
   
finally
   {
    sw.Close();
   }
   
return true;

此函数放在Conn.CS基类中了在添加新闻的代码中引用 注:工程名为Hover

    
if(Hover.Conn.WriteFilethis.Title.Text.ToString),this.Content.Text.ToString),this.Author.Text.ToString)))
    {
     Response.Write(
"添加成功");
    }
    
else
    {
     Response.Write(
"生成HTML出错!");
    }

模板页Text.html代码

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
  
<title>ShowArticle</title>
   
<body>
biaoti
<br>
content
<br>
author
</body>
</HTML>
biaoti
<br>
content
<br>
author
</body>
</HTML>

提示添加成功后会出以当前时间为文件名的html文件!上面只是把传递过来的几个参数直接写入了HTML文件中,在实际应用中需要先添加数据库,然后再写入HTML文件

方案3:给一个客户端参考的例子(SJ)

它的作用在于以客户端的方式获取某个页面的代码,然后可以做为其他用途,本例是直接输出

<script>
    
var oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    oXmlHttp.open(
"GET","http://www.webjx.com"false);
    oXmlHttp.send()
    
var oStream = new ActiveXObject("ADODB.Stream");
    
if(oStream == null)
        alert(
"您的机器不支持ADODB.Stream.")
    
else
    {
        oStream.Type
=1;
        oStream.Mode
=3;
        oStream.Open() ;
        oStream.Write(oXmlHttp.responseBody);
        oStream.Position
= 0;
        oStream.Type
= 2;
        oStream.Charset
="gb2312";
        
var result= oStream.ReadText();
        oStream.Close();
        oStream 
= null;
 
      var aa = window.open("","")
        document.write(result);
        aa.document.write(result);
    }
</script>

 

方案4:学csdn一样。用xml保存数据,模版XSL也只有一个文件。

使用xml来保存数据,使用xsl来定义模板并且生称数据。可以通过xsl来很方便的在客户端或者服务段显示数据。如果要生成静态叶面那更简单了。去查一下.net的xml类包问题解决。

优点:可以方便快速转换成你想要的格式和内容。
缺点:需要学习更多的内容,不好入门。

方案5:

思路一:

1. 利用如

这样的工具生成html格式的模板,在需要添加格式的地方加入特殊标记(如$htmlformat$),动态生成文件时利用代码读取此模板,然后获得前台输入的内容,添加到此模板的标记位置中,生成新文件名后写入磁盘,写入后再向数据库中写入相关数据。
2. 使用后台代码硬编码Html文件,可以使用HtmlTextWriter类来写html文件。

优点:

1. 可以建立非常复杂的页面,利用包含js文件的方法,在js文件内加入document.write()方法可以在所有页面内加入如页面头,广告等内容。

2. 静态html文件利用MS Windows2000的Index Server可以建立全文搜索引擎,利用asp.net可以以DataTable的方式得到搜索结果。而Win2000的Index服务无法查找xml文件的内容。如果包括了数据库搜索与Index索引双重查找,那么此搜索功能将非常强大。

3. 节省服务器的负荷,请求一个静态的html文件比一个aspx文件服务器资源节省许多。

缺点:

思路二: 如果用硬编码的方式,工作量非常大,需要非常多的html代码。调试困难。而且使用硬编码生成的html样式无法修改,如果网站更换样式,那么必须得重新编码,给后期带来巨大的工作量。

因此这里采用的是第一种思路

示列代码

1.定义(template.htm)html模板页面

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body >
<table $htmlformat[0] height="100%" border="0" width="100%" cellpadding="10" cellspacing ="0" bgcolor="#eeeeee" style="border:1px solid #000000">
<tr>
<td width="100%" valign="middle" align="left">
<span style="color: $htmlformat[1];font-size: $htmlformat[2]">$htmlformat[3]</span>
</td>
</tr>
</table>
</body>
</html>

 

2.asp.net代码:

 

//---------------------读html模板页面到stringbuilder对象里----

string[] format=new string[4];//定义和htmlyem标记数目一致的数组
StringBuilder htmltext=new StringBuilder();
try
{
   
using (StreamReader sr = new StreamReader("存放模板页面的路径和页面名"))
    {
        String line;
        while ((line = sr.ReadLine()) != null)
        {
            htmltext.Append(line);
        }
        sr.Close();
    }

catch
{
    Response.Write(
"<Script>alert('读取文件错误')</Script>");

//---------------------给标记数组赋值------------
format[
0]="background="/blog/bg.jpg"";//背景图片
format[
1]= "#990099";//字体颜色
format[
2]="150px";//字体大小
format[
3]= "<marquee>生成的模板html页面</marquee>";//文字说
//----------替换htm里的标记为你想加的内容
for(int i=0;i<4;i++)
{
    htmltext.Replace(
"$htmlformat["+i+"]",format[i]);
}
//----------生成htm文件------------------――
try
{
    using(StreamWriter sw=new StreamWriter("存放路径和页面名",false,System.Text.Encoding.GetEncoding("GB2312")))   
    {
        sw.WriteLine(htmltext);
        sw.Flush();
        sw.Close();
    }
}
catch
{
    Response.Write (
"The file could not be wirte:");
}

小结
用此方法可以方便的生成html文件。程序使用了是循环替换,因此对需替换大量元素的模板速度非常快。

 

转自:http://www.cnblogs.com/kevin-wu/archive/2007/09/14/893334.html

posted @ 2008-08-01 12:37 蓝色海岸线 阅读(53) 评论(0) 编辑
在AJAX支持的网站中使用想使用Response.Wrie(“”); 或 Page. RegisterStartupScript (); 弹出一些提示对话框,没有效果。有如下两种解决方法:
 
(1)      System.Web.UI.ScriptManager.RegisterStartupScript来替代Page.ClientScript.RegisterStartupScript
函数原型:
System.Web.UI.ScriptManager.RegisterStartupScript(Contrl control, Type type,string key,string script, bool addScriptTags);
参数:
control//要要注册此段javascript语句的控件ID,如下面示例的按钮ID btnUnReport
type//一般直接用this.GetType()即可
key//为要执行的javascirpt语句起的名字,可以随便起,类似控件的name属性
script//javascript语句
addScriptTags//为true时,前边的script参数可以不用再写javascript标签;为false,则需自己为script参数添加<script language=’javascript’></script>标签。

注:要多传一个Control参数,如果这个control在UpdatePanel里,则运行脚步,如果这个control不在UpdatePanel则不允许这段脚步
Eg.
System.Web.UI.ScriptManager.RegisterStartupScript(btnUnReport, this.GetType(), "unReport""alert('内容');window.close();"true);
 
(2)注册DataItem方法:
示例:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm1.aspx.cs" Inherits="WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    
<title>无标题页</title>
</head>
<body>
    
<form id="form1" runat="server">
    
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 
    
<script type="text/javascript">
        Sys.WebForms.PageRequestManager.getInstance().add_pageLoading( 
            
function(sender, e) 
         

                
var dataItem = e.get_dataItems()["<%= this.UpdatePanel1.ClientID %>"](); 
               alert(dataItem.Name); 
          }
); 
    
</script>
    
<div> 
        
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
            
<ContentTemplate> 
                
<asp:Button ID="test" runat="server" Text="test" OnClick="test_Click" /> 
            
</ContentTemplate> 
        
</asp:UpdatePanel> 
    
</div> 

    
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Web.Script.Serialization;

    
public partial class WebForm1 : System.Web.UI.Page
    
{
        
protected void Page_Load(object sender, EventArgs e)
       
{

        }


        
protected void test_Click(object sender, EventArgs e)
        
{
            JavaScriptSerializer serializer 
= new JavaScriptSerializer();
            ScriptManager.GetCurrent(
this.Page).RegisterDataItem(this.UpdatePanel1, "var _f = function(){alert('Hello World!');}; _f;"true);

        }


    }

(3)      使用Javascript的非模态对话框弹出提示
Eg.
Page.RegisterStartupScript("alert""<script language='javascript'>window.showModelessDialog(\"javascript:alert('内容');window.close();\",\"\",\"status:no;resizable:no;help:no;dialogHeight:height:30px;dialogHeight:40px;\")</script>"); 
posted @ 2008-08-01 12:36 蓝色海岸线 阅读(231) 评论(2) 编辑
  2008年7月28日
摘要: 1. Accordion【功能概述】 Accordion可以让你设计多个panel 并且一次只显示一个Panel .在页面上的显示效果就像是使用了多个CollapsiblePanels只不过每一次只展开其中一个CollapsiblePanel.Accordion控件内部包含了若干个AccordionPane,每一个AccordionPane的template里包括了对其Header和Content...阅读全文
posted @ 2008-07-28 12:47 蓝色海岸线 阅读(163) 评论(0) 编辑
  2008年7月16日
摘要: WMI使用技巧集 很多的朋友对WMI可能见过但理解不深,我也是十分想了解关于WMI的知识,可一直找不对太合适的资料,在网上的一些资料不是有很多错误,就是讲解不清,我有空的时候将关于WMI的知识集中一下,放在这里便于大家学习。本贴会不断增加。1、什么是WMIWMI是英文WindowsManagementInstrumentation的简写,它的功能主要是:访问本地主机的一些信息和服务,可以管理远程计...阅读全文
posted @ 2008-07-16 18:30 蓝色海岸线 阅读(124) 评论(0) 编辑
摘要: 因为平常可能在表单验证的时候,用到的比较多。特发出来,让各位朋友共同使用。呵呵。匹配中文字符的正则表达式: [\u4e00-\u9fa5]评注:匹配中文还真是个头疼的事,有了这个表达式就好办了匹配双字节字符(包括汉字在内):[^\x00-\xff]评注:可以用来计算字符串的长度(一个双字节字符长度计2,ASCII字符计1)匹配空白行的正则表达式:\n\s*\r评注:可以用来删除空白行匹配HTML标...阅读全文
posted @ 2008-07-16 18:10 蓝色海岸线 阅读(1412) 评论(1) 编辑
跟小D每日学口语
昵称:蓝色海岸线
园龄:3年10个月
粉丝:0
关注:0
<2012年2月>
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910

搜索

 

常用链接

我的标签

随笔分类

随笔档案

文章分类

相册

常用链接

最新评论

阅读排行榜

评论排行榜

推荐排行榜