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

本文介绍了一种使datagrid行在鼠标悬停时改变颜色的方法,并提供了一个JavaScript函数来根据值自动选择下拉框中的选项,还分享了计算包含中文字符的字符串长度的函数。

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();

转载于:https://www.cnblogs.com/Truly/archive/2006/04/12/373405.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值