str=str.replace(/\"/g,"");//正则去除字符串中的双引号
//用正则取地址栏参数
function GetQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
//限制文本框只能输入double类型数据
function clearNoNum(event, obj) {
//响应鼠标事件,允许左右方向键移动
event = window.event || event;
if (event.keyCode == 37 | event.keyCode == 39) {
return;
}
//先把非数字的都替换掉,除了数字和.
obj.value = obj.value.replace(/[^\d.]/g, "");
//必须保证第一个为数字而不是.
obj.value = obj.value.replace(/^\./g, "");
//保证只有出现一个.而没有多个.
obj.value = obj.value.replace(/\.{2,}/g, ".");
//保证.只出现一次,而不能出现两次以上
obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
}
function checkNum(obj) {
//为了去除最后一个.
obj.value = obj.value.replace(/\.$/g, "");
}
//限制文本框只能输入整形
//只能输入数字(正整数)
function chkPrice(obj) {
obj.value = obj.value.replace(/[^\d]/g, "");
}
function onKeyPressForDouble(o,event)
{
var keyChar = String.fromCharCode(event.keyCode);
var value = o.value;
var numstr = "0123456789.";
if (numstr.indexOf(keyChar)>-1){
if ((keyChar == ".") && (value.indexOf(".")>-1))
{
event.keyCode=0;
return false;
}
}else
{
event.keyCode=0;
return false;
}
return true;
}
1.Server.MapPath("../treejquery/demo/treegrid_data.aspx") //Server.MapPath里面是放文件的相对路径
2.文件流的操作
FileStream fs = new FileStream(Server.MapPath("../treejquery/demo/treegrid_data.aspx"), FileMode.OpenOrCreate);//文件流
//编码格式 System.Text.Encoding.GetEncoding("GB2312")一般不容易出现乱码问题
Byte[] info = System.Text.Encoding.GetEncoding("GB2312").GetBytes(hidjson.Value);//string与byte[]相互间转换
fs.Write(info, 0, info.Length); //将文件内容写入文件
fs.Flush();//刷新文件 清除缓存流
fs.Close();//关闭
3.var _html=document.getElementById("testexcel").outerHTML; //获取包含当前操作的html代码
$("#testexcel").html() //只能获取当前操作的子节点的html
//向DataSet中添加多个DataTable
4.
DataSet ds=new DataSet();
DataTable dt1 =new DataTable();
dt1.TableName = "new";
ds.Tables.Add(dt1.Copy());
DataTable dt2=new DataTable();
dt2.TableName="new2";
ds.Tables.Add(dt2.Copy());
5.distinct sqlserver数据库不重复数据关键字
6.string AllSubSort = "asdf123><dddddd126"; //正则取字符串中的数字并用逗号隔开
string strRet = "";
string pattern = "\\d+";
MatchCollection matchs = Regex.Matches(AllSubSort, pattern);
if (matchs != null)
{
foreach (Match match in matchs)
{
if (match != null)
strRet += match.Groups[0].ToString() + ",";// +match.Groups["key"].Value;
}
}
string[] ar = strRet.Split(new char[] { ',' });
this.TextBox1.Text = strRet;
7.XML对数据的操作并将table转换为dataset
str = "<?xml version=\"1.0\" standalone=\"yes\"?>" + "<table>" + str + "</table>"; //清洗
XmlDocument doc = new XmlDocument();
doc.LoadXml(str);
XmlNodeList nodes = doc.SelectNodes("//tr");
for (int j = 0; j < nodes.Count; j++)
{
XmlNode node = nodes[j];
for (int i = 0; i < node.ChildNodes.Count; i++) //列的循环,为每个列指定名称
{
XmlNode n = doc.CreateNode(XmlNodeType.Element, "col" + i.ToString(), "");
n.InnerXml = node.ChildNodes[i].InnerText;
node.ReplaceChild(n, node.ChildNodes[i]);
}
}
//导入Dataset
DataSet ds = ds = new DataSet();
StringReader tr = new StringReader(doc.InnerXml);
ds.ReadXml(tr);
DataTable dt = ds.Tables[0];
8. //XML格式字符串替换
public static string ReplaceFontSpan(string s)
{
Regex r = new Regex("<head>.*?</head>");
s = r.Replace(s, "");
r = new Regex("</?font.*?>");
s = r.Replace(s, "");
r = new Regex("</?span.*?>");
s = r.Replace(s, "");
r = new Regex("</?a.*?>");
s = r.Replace(s, "");
r = new Regex(" ");
s = r.Replace(s, "");
r = new Regex("</?tbody.*?>");
s = r.Replace(s, "");
r = new Regex("</?table.*?>");
s = r.Replace(s, "");
return s;
}
9.http://www.cainiao8.com/web/js_note/js_regular_expression_blueidea.html 正则表达式牛逼
10./// <summary>
/// 转换中文excel名称,防止乱码,兼容IE和火狐
/// </summary>
/// <param name="fileName">中文名称</param>
/// <returns></returns>
public static string GetToExcelName(string fileName)
{
string UserAgent = HttpContext.Current.Request.ServerVariables["http_user_agent"].ToLower();
if (UserAgent.IndexOf("firefox") == -1)
fileName = HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8);
return fileName;
}
11.附带下载的文件操作
private void csvfile(string table, string excelname, string _zfcs) {
string name=GetSaveFilePath();
string path = Server.MapPath("\\upload") + name + ".csv";
FileStream file = new FileStream(path, FileMode.Create);//创建文件流
Byte[] info = System.Text.Encoding.GetEncoding(_zfcs).GetBytes(table);
file.Write(info, 0, info.Length);//文件内容写入文件流
file.Flush();
file.Close();
file.Dispose();
long size = info.Length;
Response.Clear();
Response.ContentType = "application/octet-stream"; //"application/octet-stream";//octet-stream
Response.AppendHeader("Content-Disposition", "attachment;filename=" + GetToExcelName(excelname) + ".csv");
Response.AppendHeader("Content-Length", size.ToString());
Response.AppendHeader("Content-Transfer-Encoding", "binary");
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.WriteFile(path, 0, info.Length);
Response.Flush();
Response.End();
}
12. javascript 动态生成form表单以及隐藏域
function Excelbut( divid,tag,sheetname,excelname,kz,zfcs ){ //excel
var _wtb='',_html='';
var wtb=GetTableData(divid);//解析table中的colspan与rospan,还原成colspan=2为 <td>1</td> <td>2</td>
wtb=wtb.split('☆');
_wtb=wtb[0];
_html=wtb[1];
var form = P_createElement('form', {
method: 'post',
action:'http://export.yikeba.com/ToEXCELpage.aspx',
enctype: 'multipart/form-data' }, {
display: 'none' }, document.body); //_html
P_each(['hidhtml','excelname','sheetname','hidkz','tag','zfcs','wantable'], function (name) {
P_createElement('input', {
type: 'hidden',
name: name,
value: {
hidhtml:_html, //原始table中colspan=2
excelname:excelname, //'导出应付列表',
sheetname: sheetname, //'名称1|',
hidkz:kz, //'', //是否允许转化特殊格式 "true"代表要进行特殊格式化 比如DateTime类型倒出来就是日期格式
tag:tag, //导出文件参数 默认为空 为空时候就是xls 另一种是csv
zfcs:zfcs, //字符参数 默认为空 为空时候就是utf-8 另一种是gb2312
wantable:_wtb //解析table中的colspan与rospan,还原成colspan=2为 <td>1</td> <td>2</td>
}[name] }, null, form); });
// submit
form.submit();
// clean up
P_discardElement(form);
}
function GetTableData(divid){//解析table中的colspan与rospan,还原成colspan=2为 <td>1</td> <td>2</td>
var z='',z1='',yta1='',wtb='';
for(var i=0;i<$("#"+divid).find("table.my_tbl").length;i++){
if($("#"+divid).find("table.my_tbl:eq("+i+")").attr("id")==undefined){
$("#"+divid).find("table.my_tbl:eq("+i+")").attr("id","Table"+(i+1));
}
var tableid=$("#"+divid).find("table.my_tbl:eq("+i+")").attr("id");
var _ht=document.getElementById(tableid);
if(i==$("#"+divid).find("table.my_tbl").length-1){
z1+=tableid;
}else{
z1+=tableid+",";
}
var zz=P_ExcelHTMLRE(_ht.innerHTML);
if(i==$("#"+divid).find("table.my_tbl").length-1){
z+="<table>"+zz+"</table>";
}else{
z+="<table>"+zz+"</table>"+"┊";
}
}
var _html=z;
var _wtb="";
var arr=new Array();
arr=z1.split(',');
for(var i=0;i<arr.length;i++){
if(i==arr.length-1){
_wtb+="<table>"+P_ExcelHTMLRE(ReCreateTable(arr[i]))+"</table>";
}else{
_wtb+="<table>"+P_ExcelHTMLRE(ReCreateTable(arr[i]))+"</table>"+"┊";
}
}
return _wtb+"☆"+_html;
}
//将存在colspan与rowspan的table还原成完整的colspan=1 和 rowspan=1
function ReCreateTable(_id){
var _tab=$("#"+_id).html();
var s=$("#"+_id).find("tr th").length;
$("#"+_id+ " tr").each(function(trindex,tritem){
//var j=0;
$(tritem).find("td").each(function(tdindex,tditem){
var rowspanCount=$(tditem).attr("rowspan");
var colspanCount=$(tditem).attr("colspan");
var value=$(tditem).html();
if($(tditem).find("input[type=text]").val()!=undefined){value=$(tditem).find("input[type='text']").val();$(tditem).html("").html(value);}
if($(tditem).find("select").val()!=undefined){value=$(tditem).find("select").val();$(tditem).html("").html(value);}
var newtd="<td>"+value+"</td>";
if(rowspanCount>1){
var parent=$(tditem).parent("tr")[0];
if(colspanCount==undefined){colspanCount=1}
while(rowspanCount>1){
var index=$(tditem).index();
for(var i=0;i<colspanCount;i++){
$(parent).next().find("td:eq("+(index)+")").before(newtd);
}
parent=$(parent).next();
rowspanCount--;
}
$(tditem).attr("rowspan",1);
}
if(colspanCount>1){
while(colspanCount>1){
$(tditem).after(newtd);
colspanCount--;
}
$(tditem).attr("colspan",1);
}
});
$(tritem).find("td:eq("+(s-1)+")").html("");//为什么没有更改嘞?
$(tritem).find("th:eq("+(s-1)+")").html("");
});
var _newtab=$("#"+_id).html();
$("#"+_id).html("");
$("#"+_id).html(_tab);
if(_id.indexOf("Table")!=-1){$("#"+_id).removeAttr("id");}//移除属性id
return _newtab;
}
//针对于IE浏览器对table去掉双引号的问题用正则表达式加双引号
13.数据库
create proc ogn_save_mz ( @ognaid varchar(20), @ognflightinfo text, @ognadderss varchar(100), @ognoutinform text, @ognmarks text, @right char(1) ) as SET XACT_ABORT ON --强制出错全部回滚 BEGIN TRAN --内容主体
--出错处理 IF @@ERROR<>0 GOTO errhandle---->發生錯誤直接跳轉到後面,不發生錯誤提交 COMMIT TRAN set @right=1 RETURN errhandle: IF @@ERROR<>0 BEGIN ROLLBACK TRAN set @right=0 END RETURN GO
14.
使浏览器不会在本地缓存结果,response.setHeader("Cache-Control","no-cache");response.setHeader("pragma","no-cache");
15.让文本框只能输入数字(包含小数)
function chkPrice(obj) {
obj.value = obj.value.replace(/[^\d.]/g, "");
}
//只能输入数字(包含小数)
function chkPrice(obj) {
obj.value = obj.value.replace(/[^\d.]/g, "");
//必须保证第一位为数字而不是.
obj.value = obj.value.replace(/^\./g, "");
//保证只有出现一个.而没有多个.
obj.value = obj.value.replace(/\.{2,}/g, ".");
//保证.只出现一次,而不能出现两次以上
obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
}
function chkLast(obj) {
// 如果出现非法字符就截取掉
if (obj.value.substr((obj.value.length - 1), 1) == '.')
obj.value = obj.value.substr(0, (obj.value.length - 1));
}
用法:<input type='text' name='Quentity' id='Quentity' style='width:50px;' onkeyup=\"chkPrice(this);\" onblur=\"chkLast(this)\" onpaste=\"javascript: return false;\" value='" + count + "' />(onpaste=\"javascript: return false;\" 禁止使用粘贴,屏蔽右键)