我有
<asp:TextBox runat="server" ID="TextBox1" value="<%$ Resources: WebResource, Search %>" onblur="if(this.value=='') this.value='Search';" onfocus="if(this.value=='Search') this.value='';" />
我怎样才能为onblur做这样的事情
<asp:TextBox runat="server" ID="TextBox1" value="<%$ Resources: WebResource, Search %>" onblur="if(this.value=='') this.value='<%=Resources.WebResource.Search %>';" onfocus="if(this.value=='<%=Resources.WebResource.Search %') this.value='';" />
本地化JavaScript内联?
答案 0 :(得分:1)
您可以使用数据绑定表达式(<%# %>
):
<asp:TextBox
runat="server"
ID="TextBox1"
value="<%$ Resources: WebResource, Search %>"
onblur='<%# string.Format("if(this.value==\"\") this.value=\"{0}\"", Resources.WebResource.Search) %>'
onfocus='<%# string.Format("if(this.value==\"{0}\") this.value=\"\"", Resources.WebResource.Search) %>'
/>
请务必在页面上致电DataBind
。或者在后面的代码中:
TextBox1.Attributes["onblur"] = string.Format("if(this.value==\"\") this.value=\"{0}\"", Resources.WebResource.Search);
TextBox1.Attributes["onfocus"] = string.Format("if(this.value==\"{0}\") this.value=\"\"", Resources.WebResource.Search);