①cs页中操纵cookie总结
1.修改cookie:重新创建cookie,覆盖原有cookie,
2.获取cookie: HttpCookie cookie = SHttpContext.Current.Request.Cookies[name];
3.创建cookie:
HttpContext.Current.Response.Cookies.Add(new HttpCookie(name, HttpUtility.UrlEncode(content)));
HttpContext.Current.Response.Cookies[name].Expires = dtime;
②js中统计出现最多的字符次数
function CountString(str)
{
if(!str) return;
var _count = 0, _temp = 0, _reg, _char;
for(var i=0; i<str.length; i++)
{
_reg = new RegExp(str.charAt(i), 'g');
_temp = str.match(_reg).length;
if(_temp > _count)
{
_count = _temp;
_char = str.charAt(i);
}
}
return _count;
//return {count:_count, char:_char};可以返回出现最多次数的字符。
};
③三种动态添加Option的方式(转自JiGuang's Blog的博客)
第一种:new Option()构造函数
<select id="cat" name="cat" style="width:130px;"></select> //所要获得的下拉框
var gameCat = document.getElementById('cat');//获得下拉框
for(var i=0, j=gameOptions.options.length; i<j; i++){
gameCat.options[i] = new Option(gameOptions.options[i].name, gameOptions.options[i].value);
if(gameOptions.options[i].isHot == 'true')
{ gameCat.options[i].className = 'hot-games'; }
}
第二种方案:通过document.createElement()来创建选项,然后再设置选项的属性。
在这里w3c标准是可以设置option的label属性即为显示文本,但事实证明FF并不支持,只是给option增加了一个label属性。
而w3c中定义的readonly的属性text,在FF中却可以设置。那么是否需要判断浏览器类型呢?当然不用,该方案代码如下:
var gameCat = document.getElementById('cat');
for (var i = 0, j = gameOptions.options.length; i < j; i++)
{
var option = document.createElement('option'); //创建选项
try{
// 二级DOM中该属性为readonly,但FF确可写,且可显示为选项内容o
ption.text = gameOptions.options[i].name;
}
catch(e){
// IE支持label,可以直接显示为选项的文字
option.label = gameOptions.options[i].name;
}
option.value = gameOptions.options[i].value;
option.className = (gameOptions.options[i].isHot == 'true') ? 'hot-games' : '';
// 如果不传第二个参数,FF下会报错
gameCat.add(option, null);
}
第三种方案:通过innerHTML,比较少用于select元素上,IE下是无效的,但是动态添加其他元素的孩子时经常用到。当然也可以设置
元素属性后appendChild()
这里要先把select隐藏掉,这样可以减少浏览器重绘次数,对于display='none'的元素的操作不会引起重绘或回流。在改变完之后
再显示出来
var gameCat = document.getElementById('cat');
// 方案3:innerHTML// IE无效,FF可用
gameCat.style.display = 'none';
for (var i = 0, j = gameOptions.options.length; i < j; i++)
{
var isHot = (gameOptions.options[i].isHot == 'true')?'hot-games':'';
gameCat.innerHTML += '<option value='+gameOptions.options[i].value+'
className='+isHot+'>'+gameOptions.options[i].name+'</option>';
}
gameCat.style.display = 'block';
转载于:https://www.cnblogs.com/kelin418/archive/2010/12/10/1902616.html