English 中文(简体)
未通过点击活动启动的文字
原标题:script not activated by click event

Hello i在jquery撰写了一些文字,并将之约束在一次点击活动中,但该代码并未通过点击活动启动。 但是,如果将文字放在另一个Java文本功能中,并且把 Java本功能约束在点击事件聆听器上,而该功能无法在点击时执行。

Another thing is that when i bind the script using JavaScript it returns me alert message same number of time as the number of div on which i have clicked i.e. if i click on 3rd div the alert message is shown three times on my page the dom structure is of pdf.js project and this dom is created dynamically i want to get the index of grandchild of pagecontainer2 on which user had clicked following is my script:

<script type="text/javascript">
    $(function() {
        $(".textLayer > div", "#pageContainer2").click(function () {
            var index = $(this).index();
            alert("index of div is = " + index);
        });
    });
</script>

Dom CODE:

<div id="pageContainer2" >
    <canvas id="page2" width="741" height="959"></canvas>
    <div class="textLayer">
        <div>......some text here....</div>
        <div>......some text here....</div>
        <div>......some text here....</div>
    </div>
</div>

<div id="pageContainer3" >
    <canvas id="page3" width="741" height="959"></canvas>
    <div class="textLayer">
        <div>......some text here....</div>
        <div>......some text here....</div>
        <div>......some text here....</div>
    </div>
</div>​
最佳回答

如果你需要把点击事件手指派给一名尚未到场但后来将成立的OM Node,那么,你需要把活动手绑在现有的节点上,使用<条码>。

请允许我说,<div id=“pageContainer2”>已经存在,但你在该集装箱内重新制造这些灰.。 因此,适当的改变是:

$(function() {
    $( #pageContainer2 ).on( click ,  .textlayer > div , function() {
        /* .... */
    });
});

这样,你实际上将事件手对集装箱具有约束力,但是由于大多数事件都困扰着OM,用点击该集装箱内的任何部件发射的事件将到达集装箱本身。 由于你指定了另一名遴选人(`文本layer > div'),因此,如果实际要素被点击 this该选人,则会检查。

如果连第2页的“Container”是经过对事件手持约束力后设立的,那么你仍然可以把事件手对文件本身具有约束力:

$(document).on( click ,  #pageContainer2 .textlayer > div , function() { ...
问题回答

审判这一 j:

  $(function() {
        $(".textLayer").click(function () {
            var index = $(".textLayer").index(this);
            alert("index of div is = " + (index+1));
        });
    });

稍作改动。

$("#pageContainer2 > .textLayer > div").click(function () {
            var index = $(this).index();
            alert("index of div is = " + index);
        });

由于以动态方式建立了超文本,你将不得不使用<条码>。 页: 1

$(function() {
   $(".textLayer > div",  #pageContainer2 ).on( click , function () {
       var index = $(this).index();
       alert("index of div is = " + index);
   });
});




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

热门标签