我在panel里嵌入table,table里嵌入label和textbox控件
如果仅仅如此,如下代码完全胜任。
this.TextBox1 .Attributes.Add("onfocus", "m_txtreasonProcess()");
this.TextBox1.Attributes.Add("onpropertychange", "mm(this)");
<script language="javascript" type="text/javascript">
function m_txtreasonProcess()
{
var txt=document.getElementById ("TextBox1");
txt.value='';
txt.style.color="black";//haha
}
String.prototype.lenB = function()
{
return this.replace(/[^\x00-\xff]/g,"**").length;
}
function mm(e)
{
var len = e.value.lenB();
document.getElementById("Label1").innerText = (10-len) +" /10";
} </script>
但是同样的代码放到新环境就不起作用,还报错。
新环境里增加了gridview控件,单击其中的单元格后,显示如上的panel(里面
控件更多些而已)。我将this.TextBox1 .Attributes.Add("onfocus", "m_txtreasonProcess()");
this.TextBox1.Attributes.Add("onpropertychange", "mm(this)");添加在了
gridview_RowCommand(object sender, GridViewCommandEventArgs e)事件下还请各位牛人,鼎力相救!
如果仅仅如此,如下代码完全胜任。
this.TextBox1 .Attributes.Add("onfocus", "m_txtreasonProcess()");
this.TextBox1.Attributes.Add("onpropertychange", "mm(this)");
<script language="javascript" type="text/javascript">
function m_txtreasonProcess()
{
var txt=document.getElementById ("TextBox1");
txt.value='';
txt.style.color="black";//haha
}
String.prototype.lenB = function()
{
return this.replace(/[^\x00-\xff]/g,"**").length;
}
function mm(e)
{
var len = e.value.lenB();
document.getElementById("Label1").innerText = (10-len) +" /10";
} </script>
但是同样的代码放到新环境就不起作用,还报错。
新环境里增加了gridview控件,单击其中的单元格后,显示如上的panel(里面
控件更多些而已)。我将this.TextBox1 .Attributes.Add("onfocus", "m_txtreasonProcess()");
this.TextBox1.Attributes.Add("onpropertychange", "mm(this)");添加在了
gridview_RowCommand(object sender, GridViewCommandEventArgs e)事件下还请各位牛人,鼎力相救!
你看看运行后客户端的HTML代码中对应文本框的ID是什么(返回客户端得是<input type="text" .....)
然后把js中的TextBox1这个ID更改为你找到的那个ID
this.TextBox1.Attributes.Add("onpropertychange", "mm(this)");
应该改为((TextBox)Gridview.Rows.findcontral("TextBox_id")).attributes.add()不知道代码写的对不对你这个需要到GRIDVIEW里去寻找 不能直接在THIS里找
我还想知道,用正则表达式,能不能在textbox输入长度超出范围
自动屏蔽掉多余的输入
应该改为((TextBox)Gridview.Rows.findcontral("TextBox_id")).attributes.add()
{
nLen = 0;
nTemp = 0;
for (i = 0; i < strVal.length; i ++)
{
if (strVal.charCodeAt (i) > 255)
nLen += 2;
else
nLen ++;
if(nLen <= nStrLen)
nTemp = i;
else
break;
};
return(strVal.substr(0,nTemp+1));
}