您的位置:首页 > Web前端 > JavaScript

一些常用的js代码(更新中)

2006-04-12 16:32 309 查看
onmouseover="oldItemBackColor=this.style.backgroundColor;this.style.backgroundColor='#DEEFFF';" onmouseout="this.style.backgroundColor=oldItemBackColor;"

应用:datagrid的行变色
ItemCreated event

if(e.Item.ItemType != ListItemType.Header)
{
e.Item.Attributes.Add("onmouseover", "oldItemBackColor=this.style.backgroundColor;this.style.backgroundColor='#DEEFFF';");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=oldItemBackColor;");
}

根据value自动选择select的项

function searchSelectByValue(selectBox, searchValue) {
/** Searches a select combo box for the specified value; if found, it
** makes it the selected option
** truly
**/
var arOptions = selectBox.options;
var strCompare = new String(searchValue).toLowerCase();
var intCompareLen = strCompare.length;
var i, j; // loop counters

for (i = 0; i < arOptions.length; i++) {
// did we match the search string?
if (strCompare == arOptions[i].value.substring(0,
intCompareLen).toLowerCase()) {
// remove all selections
for(j = 0; j < arOptions.length; j++)
selectBox.options[j].selected = false;

// select the option that matched and exit
selectBox.options[i].selected = true
break;
}
}

if (i < arOptions.length)
return(i); // return index of match when found
else
return(-1); // return -1 to indicate no match
}

// js对含有中文的字符串长度计算
function checkVal(s){
var k = 0
for(var i=0;i<s.length;i++){
if(s.charCodeAt(i) > 255){
k += 2
}
else{
k += 1
}
}
return k;
}

EnsureChildControls();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: