简体   繁体   English

jQuery remodal popup,向URL添加标签href

[英]jQuery remodal popup adding hashtag href to url

I have a piece of html which basically looks like this: 我有一段基本上看起来像这样的html:

<a id="popap" style="display:none;" href="#modal">Call the modal with data-remodal-id="modal"</a>

And then the definition of the remodal popup like following: 然后,重新定义弹出式窗口的定义如下:

<div class="remodal" style="width:60%" data-remodal-id="modal">
    <div style="width:100%; text-align:center;">
        <canvas class="canvas" height="160"></canvas>
    </div>
    <div class="hideit">
        <button data-remodal-action="close" class="remodal-close"></button>
        <div class="row">
            <div class="modalMainTitle">
                <i class="far fa-save fa-3x"></i>
                <h1>Add to search List</h1>
            </div>
            <p>
                Comment:
            </p>
            <textarea id="TextArea1" rows="2" cols="20"></textarea>
        </div>
        <div class="row" style="padding:0 41.64% ;">
            <p>Rating: </p>
            <fieldset class="rating" id="ratingSystem">
                <input type="radio" id="star5" name="rating" value="5" autocomplete="off" /><label class="full" for="star5" title="Awesome - 5 stars"></label>
                <input type="radio" id="star4" name="rating" value="4" autocomplete="off" /><label class="full" for="star4" title="Pretty good - 4 stars"></label>
                <input type="radio" id="star3" name="rating" value="3" autocomplete="off" /><label class="full" for="star3" title="Meh - 3 stars"></label>
                <input type="radio" id="star2" name="rating" value="2" autocomplete="off" /><label class="full" for="star2" title="Kinda bad - 2 stars"></label>
                <input type="radio" id="star1" name="rating" value="1" autocomplete="off" /><label class="full" for="star1" title="Sucks big time - 1 star"></label>
            </fieldset>

        </div>
        <div class="row">
            <div class="col-lg-push-3 col-lg-6">
                <div id="infoError2" style="width:100%;text-align:center; margin-right:50px !important; padding-right:45px;" class="alert"></div>
            </div>

        </div>


        @* 0 - User watchlist //  *@
        <br>
        <button data-remodal-action="cancel" class="remodal-cancel" id="cancelButton">Cancel</button>
        <button class="remodal-confirm btnSaveWatchlist">Save</button>
    </div>
</div>

And then once I call the popup to be executed like following: 然后,一旦我调用弹出窗口,如下所示:

 $(document).on("click", ".btnWatchList", function (e) {
            $("#popap")[0].click();
    });

Once this event is completed I noticed it adds a #modal into the URL that I'm on(and I don't want that to happen). 这个事件完成后,我注意到它在我打开的URL中添加了#modal(我不希望这样)。

Once the event is fired I have a url like following: 事件触发后,我将获得如下网址:

example.com?Ids=12312312412&Date=30#modal

But the url should stay like following: 但网址应保持如下所示:

example.com?Ids=12312312412&Date=30

Is there any way I can prevent this from happening(so that the #modal part isn't added to the url once the popup shows up)? 有什么办法可以防止这种情况的发生(这样,一旦弹出窗口出现,就不会将#modal部分添加到url中)?

您也可以按照@charlietfl建议使用库提供的方法:

 <a data-remodal-target="modal" id="popap" style="display:none;" href="#">Call the modal with data-remodal-id="modal"</a>

Apologies for the first answer, I mis-read the question and have since deleted the entry (Apologies, new to this but trying to improve :) -). 抱歉,第一个答案是我误解了问题,因此删除了该条目(抱歉,这是新问题,但尝试改进:)-)。

event.preventDefault() can be used to prevent a method firing off. event.preventDefault()可用于防止方法触发。 https://www.w3schools.com/jsref/event_preventdefault.asp https://www.w3schools.com/jsref/event_preventdefault.asp

This can be attached to your Anchor Element to prevent the href being amended. 可以将其附加到您的锚元素上,以防止对href进行修改。 This would look like the following: 如下所示:

$('#popap').click(function(e){
     e.preventDefault();
}

Hopefully the above helps and apologies for the first answer :) 希望以上对第一个答案的帮助和歉意:)

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

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