如何使用 JQuery 从部分视图访问根视图中的其他元素

本文关键字:视图 其他 元素 访问 JQuery 何使用 | 更新日期: 2023-09-27 18:33:11

我有一些JQuery的部分观点...

    $("#btnCancelPayment").click(function () {
        $(this).closest('#test').show('fast');
        $(this).closest("#paymentSection").hide('fast');
    });

这个部分视图位于div 中,带有 id 的付款部分在根视图中......想知道我如何在根视图上找到除付款部分以外的其他元素...(上面的隐藏有效,但节目没有)。根视图:

<div id="test">testing </div>
<div id="paymentSection"></div>

这是JQuery...

$("#btnYesPayment").click(function () {
   ....
        $("#paymentSection").load('/Donation/AddPaymentInfo', function () {
            $("#paymentSection").show('fast');
            $('#spinner').hide();
        });
    });

有什么想法吗?谢谢!

如何使用 JQuery 从部分视图访问根视图中的其他元素

更改此行

 $(this).closest('#test').show('fast');

if($('#test').length>0){
 $('#test').show('fast');
}else console.log('there is no such element');