0

我在http://validator.w3.org中的页面显示了一个错误:

$("<input type='text' />")

为什么?我的代码无效吗?我提供一段代码。请帮忙。

<form action="{$smarty.const.APP_URL}user/login/" method="post">
    <table style="margin:0 auto 0 auto;">
        <tr>
            <td><input type="text" size="25" name="user_login" value="Tw&#243;j login" onfocus="javascript:if(this.value=='Tw&#243;j login')this.value='';" onblur="javascript:if(this.value=='')this.value='Tw&#243;j login';" /></td>
            <td><input type="password" size="25" name="user_password" id="password" /></td>
            <td><input type="submit" class="btnLogin" value="" /></td>
        </tr><tr>
            <td colspan="3">
                <p align="right"><a href="{$smarty.const.APP_URL}user/register/">utwórz konto</a> | <a href="{$smarty.const.APP_URL}user/password-reminder/">zapomniałem hasła</a></p>
            </td>
        </tr>
    </table>
</form>
{/if}
{literal}
<script type="text/javascript">
    $(document).ready(function() {
        ("<input type='text' />")
            .attr("name", "password_mask")
            .attr("id", "password_mask")
            .attr("size","25")
            .val("Twoje has\u0142o")
            .insertAfter("#password");

        $("#password_mask").focus(function() {
            $(this).hide();
            $("#password").show().focus();
        });

        $("#password").hide().blur(function() {
            if($(this).val().length == 0) {
                $(this).hide();
                $("#password_mask").show();
            }
        });
    });
</script>
{/literal}
</div>
4

3 回答 3

0

你有一个$缺失:

$(document).ready(function() {
    ("<input type='text' />")
---^

将其替换为:

$(document).ready(function() {
    $("<input type='text' />")

可能是{/if}{literal}smarty PHP 标签可能不会被 JavaScript 解析,如果它们没有被 Smarty 解析的话!

于 2013-02-10T15:36:51.220 回答
0

这不是丢失$,而是验证器不解析 JS - 当它看到“”时,它会将其视为 html 节点 - 尝试将您的 javascript 移动到外部文件

于 2013-02-10T15:51:53.280 回答
0

根据您拥有的 DOCTYPE,JavaScript 代码可能需要像这样包装:

<script type="text/javascript">
<!--
    $(document).ready(function() {
        $("<input type='text' />")
        //...
    });
//-->
</script>

这将有效地告诉 HTML 验证器忽略内容。

于 2013-02-10T15:55:27.793 回答