简体   繁体   中英

JQuery Click event didnt respond

I have a little issue with a JQuery event. I'd like too load a HTML page in a div on a button click . Button's are created dynamically with an xslt for each and the scritp too. In the browser all is well interpreted, but the event didn't work.

 $(document).ready(function(){ console.log('partie1'); $('#Btn_MILENG').click(function(){ console.log('partie2'); $( "#DIV_DETAIL" ).html('<object data="SomeURL"></object>' ); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <a class="btn btn-primary btn-xs" href="#" role="submit" name="Btn_MILENG">Détails</a> 

If someone see's the problem, it would be very helpfull for me.

your link dont have an Id

Either add an Id="Btn_MILENG" to your link , or change $('#Btn_MILENG') ==> $('[name="Btn_MILENG"]')

 $(document).ready(function() { console.log('partie1'); $('#Btn_MILENG').click(function() { console.log('partie2'); $("#DIV_DETAIL").html('<object data="SomeURL"></object>'); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <a class="btn btn-primary btn-xs" href="#" role="submit" id="Btn_MILENG" name="Btn_MILENG">Détails</a> 

You just dont given Id to element

change your line to

<a id="Btn_MILENG" class="btn btn-primary btn-xs" href="#" role="submit" name="Btn_MILENG">Détails</a>

you need to add id tag

<a class="btn btn-primary btn-xs Btn_MILENG" href="#" role="submit"  id="Btn_MILENG">Détails</a>

or you can use class

$(document).ready(function(){ 
console.log('partie1');
    $('.Btn_MILENG').click(function(){
    console.log('partie2');
           $( "#DIV_DETAIL" ).html('<object data="SomeURL"></object>' );
        });  
    });

and if you want to use id

 $(document).ready(function(){ 
console.log('partie1');
    $('#Btn_MILENG').click(function(){
    console.log('partie2');
           $( "#DIV_DETAIL" ).html('<object data="SomeURL"></object>' );
        });  
    });

both will work

Because you add button dynamicaly you should use on event. And also if your mean of button is a link, then should add ID to the a tag:

$(document).ready(function(){ 
    console.log('partie1');
        $(document).on("click", '#Btn_MILENG', function(){
        console.log('partie2');
               $( "#DIV_DETAIL" ).html('<object data="SomeURL"></object>' );
            });  
        });
<a  id="Btn_MILENG" class="btn btn-primary btn-xs" href="#" role="submit" id="Btn_MILENG" name="Btn_MILENG">Détails</a>

您尚未在Button元素中添加id属性

<a class="btn btn-primary btn-xs" href="#" role="submit" name="Btn_MILENG" id="Btn_MILENG">Détails</a>

in The body :

                    <ul>                
                        <xsl:for-each-group select="//dbquery[@id='Analyse_Global']/rows/row" group-by="@bde">
                            <xsl:variable name="BDE" select="current-grouping-key()"/>
                            <xsl:variable name="BDE_Percent" select="round(sum(//dbquery[@id='Analyse_Global']/rows/row[@bde=$BDE]/@OpsPercent) div count(//dbquery[@id='Analyse_Global']/rows/row[@bde=$BDE]))"/>
                        <li>

                            <xsl:value-of select="current-grouping-key()"/><br/><xsl:value-of select="concat($BDE_Percent,' %')"/>
                            <br/>

                            <a class="btn btn-primary btn-xs" href="#" role="submit">
                            <xsl:attribute name="id"><xsl:value-of select="concat('Btn_',current-grouping-key())"/></xsl:attribute>Détails</a>

in the head :

<xsl:for-each-group select="//dbquery[@id='Analyse_Global']/rows/row" group-by="@bde">
    <xsl:variable name="BDE" select="current-grouping-key()"/>
    <script>      
        $(document).ready(function(){ 
console.log('partie1');
    $(document).on("click", '#Btn_<xsl:value-of select="$BDE"/>', function(){
    console.log('partie2');
           $( "#DIV_DETAIL" ).html('<object data="http://opsnode.mil.intra/LRF/XMLWeb/ProcessDescriptor/descriptor/OPSNODE/LCC_STUURBOARD/LCC_STUURBOARD_DETAIL.xml?pRID=100118&amp;pLANG=FR&amp;pBde={$BDE}"></object>' );
        });  
    });
</script>
</xsl:for-each-group>

我发现了问题,但没有找到解决方案...我动态生成了一个UL LI,然后从caprica orgchart中输入tre JS,生成了一张表格来绘制orgchart ...我认为所有这些动态生成的东西都没有触发点击功能...我不怎么听正确的元素,这是正确的...

Problem solved !

the JS who create the orgchart, put a "< a> " to have is td clickable... and i try to put a < a> in it , when i finnaly see it , i put my second < a> into a span and this solved the problem. Tks to all !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM