繁体   English   中英

如何在外部javascript链接的同一类div中添加ID?

[英]How to add an ID in a same class of div in a external javascript link?

我的html中有一个javascript链接,该链接来自第三方。 我无法直接在javascript链接中编辑html,但可以使用CSS,Javascirpt或Jquery进行编辑,删除或添加。

javascript链接是:

<div class="fluid-container" style="margin-top:10px;">
        <div class="fluid-container-info">          
            <script src="https://worldtravelink.com/client.ijs?userId=2&amp;resultPage=https://www.ezeerooms.in/m/result.html&amp;state=payment&amp;currency=INR&amp;ver=1.0&amp;confirmPage=https://www.ezeerooms.in/m/confirm.html" type="text/javascript"></script>
        </div>        
    </div>

我使用Firebug在javascript链接中找到了以下html代码。 我已经删除并编辑了该html的冗长部分。

<div class="wrapper_RightZone">
    <div class="PackageInfoBox">
        <div class="hotel_Package_info_Price">
            <div class="Price_Box">               
                <div class="Price">
                    <font class="PriceElement">23285.33</font>
                    <font class="CurencyElement">INR</font>
                </div>               
            </div>
        </div>       
    </div>   
    <div class="payment-title">
        <div class="StrongClass PaymentDetailsTitle"><button>Payment details</button></div>
    </div>   
    <div class="PackageInfoBox">
        <div class="RoomType_PriceRow">               
            <div class="Cel1Right">Content</div>
        </div>       
        <div class="gm_wrapper">
            <div>
                <div class="subpayment-title">               
                    <div class="StrongClass PaymentOptionTitle"><button>Payment options</button></div>                 
                </div>
                <div class="PackageInfoBox">
                    <div class="Payment_OptionsBox">
                        <div class="pay_credit" id="pay_credit">Content</div>
                    </div>    
                </div>                  
            </div>
        </div> 
    </div>
</div>

我已经通过CSS和Javascript进行了一些修改。 我要切换PackageInfoBox DIV(class =“ PackageInfoBox”),然后单击“ subpayment-title” DIV。 但是问题是同一个类名,即PackageInfoBox。 有四个PackageInfoBox类,因此无法标识我要切换的最后一个PackageInfoBox DIV。 因此,我已使用此jquery函数在最后一个PackageInfoBox DIV中添加ID。

<script type="text/javascript">
$(document).ready(function() {
     $(".gm_wrapper .PackageInfoBox").attr("id","SomeID");
});
</script>

并使用此jquery函数来切换PackageInfoBox DIV。

<script>
$(".subpayment-title").click(function(){
  $("#SomeID").toggle();
});
</script>

但是它不起作用,并且在最后一个PackageInfoBox DIV中未创建ID(SomeID)。

有人可以帮助我吗?

如果您要PackageInfoBox的最后一个元素,请使用此代码

<script type="text/javascript">
    $(document).ready(function() {
         $(".PaymentOptionTitle").on('click',function(){
            $(this).closest('.subpayment-title').next().next().slideToggle();
         });
    });
   </script>

DEMO

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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