English 中文(简体)
Javascript无效标签错误
原标题:Javascript invalid label error

如果这个问题是其他问题的重复,我很抱歉。我已经调查了其中一些,但他们没有回答我的特定问题。

我在下面的代码中打印警报语句时遇到“无效标签”错误:

    $(document).ready(
    function(){
        if( $( map#map ).length > 0 ){
            //alert( found a map! );
            $( map#map area ).each($area,
                function(i, val){
                    alert( Found:   + val ):
                }
            );
        }
    }
);

我得到的相同错误是我做了以下操作:<code>alert(Found:+$(this))

有人能告诉我为什么会发生这种事吗?

ps:我试图阅读的内容如下:

<map id="map" name="imgmap20116293122">
<area alt="" coords="11,76,97,127" href="" shape="rect" target="" title="" />
<area alt="" coords="12,28,96,74" href="" shape="rect" target="" title="" />
<area alt="" coords="100,28,160,73" href="" shape="rect" target="" title="" />
<area alt="" coords="162,28,221,73" href="" shape="rect" target="" title="" />
<area alt="" coords="502,239,549,282" href="" shape="rect" target="" title="" />
<area alt="" coords="473,284,554,330" href="" shape="rect" target="" title="" /-->

最佳回答

语句末尾有一个冒号。把它改成分号。

此外,在each方法中还有一个额外的参数$area,这是不受支持的。如果删除它,代码就会运行。

问题回答

您得到的是:而不是。改变

alert( Found:   + val ):

alert( Found:   + val );

另请参阅标签@MDC文档

您用冒号代替分号:

alert( Found:   + val );




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.