datalist里的text:
<input type="text" id="txthuifu" style="color:Gray; width:420px; height:22px;" onfocus="onfocustxthf();" onblur="onblurtxthf();" value="回复" />我用JS方法来控制的
function onfocustxthf()
{
    var txt=document.getElementById("txthuifu");
    if(txt.value=="回复")
    {
        txt.value="";
        txt.style.color="black";
        txt.style.width="420px";
        txt.style.height="45px";
    }
}

function onblurtxthf()
{
    var txt=document.getElementById("txthuifu");
    if(txt.value=="")
    {
        txt.value="回复";
        txt.style.color="gray";
        txt.style.width="420px";
        txt.style.height="22px";
    }
}这样写的问题是只有datalist最上面的一个text有变化,其余的都没有变化,我怎样才能知道我点的是哪个text呢?

解决方案 »

  1.   

    把JS 的方法绑定到每个textbox的onblur事件上就可以了
      

  2.   

    你的问题解决起来很简单,datalist 的控件模板里不要写ID(因为最终生成的HTML元素的ID要唯一),然后把 onblur 事件和 onfocus 事件都改成:onfocus="onfocustxthf(this);" onblur="onblurtxthf(this);"
    把 JS 方法的声明改为需要接受一个参数,如:
    function onfocustxthf(txt)
                {
                    if(txt.value=="回复")
                    {
                        txt.value="";
                        txt.style.color="black";
                        txt.style.width="420px";
                        txt.style.height="45px";
                    }
                }
    是不是可以了?