例如:(特別注意在設置初始值的時候 Value 中的V要大寫)
@Html.TextBoxFor(model => model.CustomerCode, new { Value=" 請輸入您的客戶號!",@style="width:240px;height:35px;",id="UserCode", @class="search_key_content"})
給TextBoxFor設置默認值,當鼠標點擊時默認值消失:
<script type="text/javascript">
$(function () {
$("#Content").html("在這里輸入默認值");
});
</script>
$(function () {
$("#Content").html("在這里輸入默認值");
});
</script>
<div class="label">@Html.LabelFor(model => model.Content)</div>
<div class="ctrl">@Html.TextAreaFor(model => model.Content, new {style = "border:1px solid #6CABE7; width:400px; height:150px;",onblur="if(this.innerHTML==''){this.innerHTML='在這里輸入默認值';this.style.color='#D1D1D1'}", onfocus="if(this.innerHTML=='在這里輸入默認值'){this.innerHTML='';this.style.color='#000'}"})
@Html.ValidationMessageFor(model => model.Content)
@Html.DisplayDescriptionFor(model => model.Content) <br /> 內心獨白可以是一篇日記,一段讓你心動的歌詞,一句座右銘, 或者一個有意思的簽名檔,<br />但是不要少於20字,也不要超過1000字。 <br />
</div>
<div class="ctrl">@Html.TextAreaFor(model => model.Content, new {style = "border:1px solid #6CABE7; width:400px; height:150px;",onblur="if(this.innerHTML==''){this.innerHTML='在這里輸入默認值';this.style.color='#D1D1D1'}", onfocus="if(this.innerHTML=='在這里輸入默認值'){this.innerHTML='';this.style.color='#000'}"})
@Html.ValidationMessageFor(model => model.Content)
@Html.DisplayDescriptionFor(model => model.Content) <br /> 內心獨白可以是一篇日記,一段讓你心動的歌詞,一句座右銘, 或者一個有意思的簽名檔,<br />但是不要少於20字,也不要超過1000字。 <br />
</div>