动态输出javascript
本页面定义为javascript.aspx
<%@ Page Language="C#" AutoEventWireup="true" %> <% string protype = "var rows=["; for (int i = 0; i < 100; i++) { protype += "{name:'tich_" + i + "',values:'wabt" + i + "iso59-1'}"; if (i < 99) protype += ","; } protype += "];"; Response.Clear(); Response.ContentType = "text/javascript"; Response.ContentEncoding = Encoding.UTF8; Response.Write(protype); Response.End(); %>
<!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>动态输出javascript内容</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script> <script type="text/javascript" src="javascript.aspx"> </script> </head> <body> <script type="text/javascript"> alert(rows.length); </script> <div id="content"> </div> </body> </html>