2011-06-17 86 views
0
  <%= Html.TextBox("txtWeight", EmployeeInformation.Weight, new { style = "font-family:Verdana;font-size:9px;", @onfocus = "this.value=''", @onmouseover = "jsWeight()", @readonly= (ViewData["flag"].ToString().CompareTo("true")==0 ? true : false) })%> 

如何基于condidtion启用或禁用文本框

  <%= Html.TextBox("txtWeight", EmployeeInformation.Weight, new { style = "font-family:Verdana;font-size:9px;", @onfocus = "this.value=''", @onmouseover = "jsWeight()", @readonly= ViewData["flag"].ToString()) })%> 

上面的代码我米使用显示在文本框的信息,因为你可以看到我米使用的onfocus和的onmouseover让我可以在工具提示中显示数据,我使用@readonly来确保文本框可以或不可以基于条件进行编辑。 但这不适合我。 我已经检查了viewData的值,这是正确的。正如我传递给它。 我已经使用禁用以及试过,但是当我米使用禁用我每次 获得的价值为禁用,当我米使用禁用我的FOUCS事件不工作

回答

0

你不能依靠@readonly@disabled为他们基本上只是通过在场使得领域只读或禁用。虽然正确的语法应为:

<input readonly="" /> 
<input disabled="" /> 

或者干脆:

<input readonly /> 
<input disabled /> 

它的更好,如果你不完全的忽略这些属性

<input readonly="readonly" /> 
<input disabled="disabled" /> 

同样的结果可以与实现t希望字段是只读或禁用的。

+0

如何使用它并填写数据。 我给出的代码包含EmployeeInformation.Weight,这是我想用文本框填充的数据,你可以告诉我如何使用这个 – 2011-06-17 08:22:08

相关问题