我现在的DataGrid有两个摸板列.
均放置了一个TextBox, ID分别是:TxtYearNum ,TxtCompute
我想在鼠标移开TxtYearNum时,自动为TxtCompute赋值(TxtCompute=TxtYearNum+2)我在ItemDataBind中增加代码:
foreach( DataGridItem di in DataGrid1.Items)
{
   TextBox txtYearNum;
   txtYearNum = (TextBox)di.FindControl("TxtYearNum");
   string s = txtYearNum.Parent.ClientID;
   string[] a =txtYearNum.Parent.ClientID.Split('_');
   string txtYearNumID = a[0]+"__"+a[2]+"__txtYearNum";   TextBox txtCompute;
   string[] aa = txtCompute.Parent.ClientID.Split('_');
   string txtComputeID = aa[0]+"__"+aa[2]+"__txtCompute";   txtYearNum.Attributes.Add("onblur","compute('"+txtYearNumID+"','"+txtComputeID+"');");
}.js函数:
function compute(txt1, txt2)
{
  alert('hi');
  txt2.value = txt1.value;
}

解决方案 »

  1.   

    function compute(txt1, txt2)
    {
    alert("hi");
    if(txt1.value = null)
    {
    alert('kong');
    }
    else
    {
    alert('not kong!');
    txt2.value = txt1.value;
    alert(txt1.value);
    }
    }这样的话是:
    弹出 not kong!
    然后弹出: undefined可是txt1.value不空啊
      

  2.   

    if(txt1.value == null)是==,而不是=
      

  3.   

    多谢楼上.
    的确是少了=
    现在是
    if(txt1.value = null)
    {
       alert('kong');
    }结果是真反了个 'kong'我现在郁闷的是我怎么取不到txt1.value.
      

  4.   

    compute('"+txtYearNumID+"','"+txtComputeID+"')
    改为
    compute("+txtYearNumID.ClientID+","+txtComputeID.ClientID+")
      

  5.   


    var a=document.getElementById(txt1)
    var b=document.getElementById(txt2)
      

  6.   

    不明白程序为什么那样写:
    把下面的改为
    foreach( DataGridItem di in DataGrid1.Items)
    {
       TextBox txtYearNum;
       txtYearNum = (TextBox)di.FindControl("TxtYearNum");
       string s = txtYearNum.Parent.ClientID;
       string[] a =txtYearNum.Parent.ClientID.Split('_');
       string txtYearNumID = a[0]+"__"+a[2]+"__txtYearNum";   TextBox txtCompute;
       string[] aa = txtCompute.Parent.ClientID.Split('_');
       string txtComputeID = aa[0]+"__"+aa[2]+"__txtCompute";   txtYearNum.Attributes.Add("onblur","compute('"+txtYearNumID+"','"+txtComputeID+"');");
    }改为
    foreach( DataGridItem di in DataGrid1.Items)
    {
    TextBox txtYearNum;
    txtYearNum = (TextBox)di.FindControl("TxtYearNum");
    string txtYearNumID = txtYearNum.ClientID; TextBox txtCompute;
    txtCompute = (TextBox)di.FindControl("txtCompute");
    string txtComputeID = txtCompute.ClientID; txtYearNum.Attributes.Add("onblur","compute('"+txtYearNumID+"','"+txtComputeID+"');");
    }
    不就行了。干嘛还要分割
      

  7.   

    JS取值一向默认取的是NAME,而不是ID,所以要根据ID取,只能getElementByIdvar a=document.getElementById(txt1)
    var b=document.getElementById(txt2)