0

我有一个Razor 语法的注册表单,如下所示

    <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=" Password " 和 id=" VerifyPassword " 的值不会被发送到服务器。在删除占位符属性时它工作正常,即数据被发送到服务器。在不删除占位符属性的情况下是否有任何解决此问题的方法?如果没有,除了 like 之外还有其他保留占位符的方法placeholder = "Verify Password"吗?

4

1 回答 1

0

placeholder属性是 html5 中的一个新属性,这意味着 html5 之前的浏览器将无法使用它们。您可以尝试一下Modernizr,它旨在使仅 HTML5 的元素/属性在较旧的浏览器上工作。当然你可以为占位符制作自己的javascript函数,这不是很困难。jsFiddle 示例

于 2013-05-26T09:34:43.200 回答