English 中文(简体)
Java本与Click dont触发功能产生的超文本
原标题:JavaScript generated HTML with onClick doesn t trigger function

以下文字在你点击连接点时增加了一个阵列的物项,并提出了作为html输出的物项清单。 http://jsfiddle.net/dqFpr/“rel=“nofollow noreferer” http://jsfiddle.net/dqFpr/。

我试图设立一个职能,从名单上删除项目。 并非涉及ice的艰巨任务,但有些点点击删除链接,则引发<条码>测试_功能()。

Can someone tell me what I am doing wrong, or show me another way of triggering the function? Your help is really appreciated ;-)

<script language="javascript">
    $(document).ready(function() {
        function test_function( number ) {
            /* This function is not triggered, nothing works inside here!! */
        }
    });

    var lines = [];
    function update_list( lines ) {
        var thecode =   ;
        for(var i = 0; i < lines.length; i++) {
            thecode = thecode + lines[i] +   <a onclick="javascript:test_function( +i+ )" href="#">(delete)</a><br /> ;
        }
        $( div#display ).html(thecode);
    }

    $( a#new ).click(function() {
        lines.push( another line );
        update_list(lines); 
    });
</script>

<div id="display"></div>
<a href="#" id="new">Add a new line</a>
最佳回答

由于在分配给的<<><><>>> > 内部超文本中,* 测试_功能* 只是由“超文本”评价的简单文本。 此时此刻,其范围是全球性的,而不是在《国际环境法》通过后到<代码>$(文件)/code>。 你们可以通过使这一职能具有全球性来确定:

$(document).ready(function(){

    window.test_function = function (number) { 
      // do stuff
    }
    ....
});

var test_function;
$(document).ready(function(){

    test_function = function (number) { 
      // do stuff
    }
    ....
});

或者,你想要获得这一功能的任何方法。 但是,虽然在匿名职能范围内申报,但你只能从这一职能中获取,而这一职能已关闭了这一范围的变量。

问题回答

暂无回答




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

热门标签