2013-05-21 88 views
0

的替代方法,我在剃刀語法登記表如下圖所示保持的Html佔位

<div id="RegisterDiv" class="is-hidden"> 
    @using (Html.BeginForm("Register", "User", FormMethod.Post, new { id = "frmRegister" })) 
    {    

     <label>Email</label> 
     @Html.TextBoxFor(lm => lm.Email, new { id = "Email", name = "Email", value = "", placeholder = "Enter your email" }) 
     <small id="Emailerror" class="error is-hidden">A valid email address is required</small> 

     <label>Password</label> 
     @Html.PasswordFor(lm => lm.Password, new { id = "Password", name = "Password", value = "", maxlength = "20" }) 
     <small id="Passworderror" class="error is-hidden"></small>  
     @Html.PasswordFor(lm => lm.VerifyPassword, new { id = "VerifyPassword", name = "VerifyPassword", value = "", maxlength = "20" }) 
     <small id="VerifyPassworderror" class="error is-hidden"></small> 
     <small class="help-block">* must be 6-20 characters (letters, numbers and hyphens are accepted but not spaces)</small> 

     <hr> 
     <div class="form-row"> 
      <div class="six columns"> 
       @Html.TextBoxFor(lm => lm.FirstName, new { id = "FirstName", name = "FirstName", value = "", placeholder = "First Name" }) 
       <small id="FirstNameerror" class="error is-hidden">First name is required</small> 
      </div> 
      <div class="six columns"> 
       @Html.TextBoxFor(lm => lm.LastName, new { id = "LastName", name = "LastName", value = "", placeholder = "Last Name" }) 
       <small id="LastNameerror" class="error is-hidden">Last name is required</small> 
      </div> 
     </div> 
     <div class="form-row"> 
      <div class="six columns"> 
       @Html.DropDownListFor(dr => dr.CountryId, new SelectList(Model.CountryList, "countryid", "name"), "Country of Residence", new { id = "CountryId", name = "CountryId" }) 
       <small id="CountryIderror" class="error is-hidden">Country is required</small> 
      </div> 
     </div>    
     <div class="form-action"> 
      <a id="Submit" class="form-submit" href="javaScript:void(0);">Register</a> 
      <a id="Cancel" class="form-cancel" href="javaScript:void(0);">Cancel</a> 
     </div> 
    } 
</div> 

並提交代碼

$("#frmRegister").submit(); 

但是,當應用程序在IE-運行8元素的值id =「密碼」和id =「VerifyPassword」沒有被髮送到服務器。關於刪除佔位符屬性它工作正常,即數據被髮送到服務器。有沒有解決這個問題與刪除佔位符屬性?如果不是,有沒有其他的方式來保持佔位符,而不是像placeholder = "Verify Password"

回答

0

placeholder屬性是html5中的一個新屬性,這意味着html5之前的瀏覽器將不能使用它們。 您可以嘗試一下Modernizr,它意味着讓純HTML5的元素/屬性在舊版瀏覽器上可用。 當然,您可以爲佔位符創建自己的JavaScript函數,但並不是非常困難。 jsFiddle example