【问题标题】:How to access other elements in root view from partial view with JQuery如何使用 JQuery 从部分视图访问根视图中的其他元素
【发布时间】:2012-05-05 02:50:17
【问题描述】:

我对一些 JQuery 有部分看法......

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

这个部分视图位于根视图中 id 为 paymentSection 的 div 中...想知道如何在根视图上找到除 paymentSection div 之外的其他元素...(上面的隐藏有效,但显示没有)。根视图:

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

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

这是 JQuery...

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

有什么想法吗?谢谢!

【问题讨论】:

  • 你有多个ids吗?如果是,则删除它们

标签: c# jquery asp.net-mvc-3 views show


【解决方案1】:

改变这一行

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

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

【讨论】:

  • 谢谢,这很有用。我的代码一开始就草率,这有帮助。
猜你喜欢
  • 1970-01-01
  • 2022-08-02
  • 2018-08-08
  • 1970-01-01
  • 2011-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多