English 中文(简体)
Java曲Eval(产生未预料到的毒性)
原标题:JavaScript Eval() generating Unexpected Token ) error

我对以下几条法典有问题,我很想知道我做什么错了。

I m 带上电传电线的错误。

function myfunction(){
    var p1 =   ;
    var p2 =   ;
    var p3 =   ;

    for (i=1; i<=3; i++){
        eval("$( #p"+i+" ).closest( .filter ).find( .vals div ).each(function(){if ($.trim(p"+i+").length > 0) {p"+i+" +=  , ;} p"+i+" += $(this).attr( class );});");
    }
}

Here is the applicable HTML:

<div class="filter">
    <label>Organizations</label>
    <input id="p1" type="text" value="" />
    <div class="vals">
        <div class="3" title="Click to remove">ABC School District</div>
        <div class="4" title="Click to remove">DEF School District</div>
    </div>
</div>
<div class="filter">
    <label>Groups</label>
    <input id="p2" type="text" value="" />
    <div id="vals"></div>
</div>

如果是完全明显的,我也在这里使用 j。

增 编

最佳回答

更不用使用阵列,而只是通常执行守则:

function myfunction(){
    var p  = [null,   ,   ,   ]; //Empty zeroth element to keep your 1-indexing

    for (i=1; i<=3; i++){
        $( #p +i).closest( .filter ).find( .vals div ).each(function(){
            if ($.trim(p[i]).length > 0) {
                p[i] +=  , ;
            }
            p[i] += $(this).attr( class );
        });
    }
}
问题回答

页: 1

function myfunction(){
    var p1 =   ;
    var p2 =   ;
    var p3 =   ;

    for (i=1; i<=3; i++){
        $("#p"+i).closest(//..... rest here

您可能失踪“......”。

 eval("$( #p" + i + " ")...

妇联:你不把职能和链条nes开,反而更容易将其分为几条不同的编码线和使用指定的职能。





相关问题
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.

热门标签