簡體   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