开发者

Why does this simple JQuery code throw an error?

<script type="text/javascript">
    $(function(){
        for(var i=0;i<7; i++){
            var guy_html = '<div class="aname"><input type="text" class="chatter_input autofriend" name="guy'+String(i) + '" /></div>';
            $("div#guy_boxes").append(guy_html);
        }
    });
</script>

<div id="guy_boxes"></div>

I just want 7 input boxes created and put into the div.

Uncaught Syntax开发者_高级运维 error, unrecognized expression: #


Syntax error, unrecognized expression is an error that gets thrown by Sizzle (jQuery's selection engine) when you have a poorly constructed selector. Getting it to trip over a # can happen if it comes at the end of your selector:

$("div#").append(guy_html);

However, your code looks okay. You may want to check other sections of javascript.


just ran this through jsfiddle and it works fine and without errors :) http://jsfiddle.net/vM4qU/


Maybe you did this in another part of the code

#("selector")

instead of

$("selector")

That would throw the error you described.


It isn't this part of code, because it's working fine here. You should search in different snippets of your code

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜