"空"值在IE中的表单字段中显示 [英] "null" values shown in form fields in IE
问题描述
我使用Html助手在表单字段中显示模型数据,例如Html.TextBoxFor,Html.TextAreaFor。
当模型值为null时,我希望这些值在表单字段中应该是空的。它们通常在Safari和Firefox中显示,即空的,但在IE中,它们在文本字段中显示为空白(请参见下面的图片)。
任何线索如何解决这个问题?谢谢。
嗯,它原来是JavaScript的问题(用IE浏览器,就是这样)。在下面的语句中,如果 value == null
,IE会在文本框(或者textarea)中显示 null
。
$('#someTextBox')。val(value);
快速修正仅仅是显示一个空字符串...
$('#someTextBox')。val(value == null?':value);
I use Html helpers to display model data in form fields, e.g. Html.TextBoxFor, Html.TextAreaFor.
When the model values are null, I would expect the values should be empty in the form fields. They are displayed normally in Safari and Firefox, i.e. empty, but in IE, they are shown as "null" in a text field (see image below).
Any clue how to fix this? Thanks.
Well, it turned out to be JavaScript's problem (with IE, that is). In the following statement, if value == null
, IE would display null
in the textbox (or textarea).
$('#someTextBox').val(value);
The quick fix is simply display an empty string instead...
$('#someTextBox').val(value == null ? '' : value);
这篇关于"空"值在IE中的表单字段中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!