簡體   English   中英

在 Modal 打開后運行 JS

[英]Running JS AFTER Modal is open

我嘗試了很多方法,例如:

$(document).ready(function () { 
 $('body.modal-open').on('shown.bs.modal', function (e) {
        if ($("a.address").length) {
        var signupText = (hightestCount);
        $(".rg-modal-signup h2").text('Keep searching ' + signupText + ' real estate.');
    } else {
        var signupText = '';
         $(".rg-modal-signup h2").text('Keep searching for your dream home.');
    }
  }); });

和:

$('body.modal-open').on('shown', function(){
if ($("a.address").length) {
        var signupText = (hightestCount);
        $(".rg-modal-signup h2").text('Keep searching ' + signupText + ' real estate.');
    } else {
        var signupText = '';
         $(".rg-modal-signup h2").text('Keep searching for your dream home.');
    } });

只是不起作用,我似乎只能在按鈕提示模態時使其運行代碼,但當模態以不同方式顯示時則不行。 有什么建議么?

給你的模態一個 id 並嘗試使用 JQuery's:visible 方法。

if($('#modal').is(":visible")){

    if ($("a.address").length) {
        var signupText = (hightestCount);
        $(".rg-modal-signup h2").text('Keep searching ' + signupText + ' real estate.');
        } else {
        var signupText = '';
        $(".rg-modal-signup h2").text('Keep searching for your dream home.');
     }

}

如果你堅持使用boostrap的方法

$(document).ready(function () { 
    $('body').on('shown.bs.modal', function (e) {
        if ($("a.address").length) {
        var signupText = (hightestCount);
        $(".rg-modal-signup h2").text('Keep searching ' + signupText + ' real estate.');
} else {
    var signupText = '';
     $(".rg-modal-signup h2").text('Keep searching for your dream home.');
}
}); });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM