使用jquery实现局部刷新DIV

实现页面的定时刷新功能:jquery使用的是jquery-1.8.3.min.js
1:定时刷新

A界面的一段代码如下:
<script type="text/javascript">
       $(document).ready(function () {
           fresh();
       });
       function fresh() {
           var id = $("#main").attr("rackId");
           $("#main").load("/RackLocations/kczt_refresh/" + id);
           setTimeout("fresh()", 1000 * 20);
       }        
    </script>
在界面中,需要刷新的DIV的ID是main。

2:加载内容
使用JQUERY的LOAD方法,加载新内容。这里的KCZT_REFRESH.cshtml由一个DIV构成及需要刷新的DIV内容。
这里采用MVC模式(C#),kczt_refresh.cshtml的内容如下:
@model IEnumerable<Wms.RackLocation>

@{
    Layout = null;
   
}
    <table id="table5" border="0" cellpadding="0" cellspacing="0" onselectstart="return false;">
    @foreach (var gp in Model.GroupBy(x => x.Level).OrderByDescending(x => x.Key))
    {
        <tr>
            @foreach (var loc in gp.OrderBy(x => x.Column))
            {      
                <td href="#details" class="loc fancybox fancybox.ajax @status(loc.kczt)  @(loc.IsLoaded ? "IsLoaded" : "")" userCode="@loc.UserCode" title="@title(loc)"  pz-gg-xs="@loc.pz@loc.gg@loc.xs">
                <div style="width:22.8px;height:32px;"></div>
                </td>
            }
        </tr>
    }
    </table>
@helper status(string kczt)
    {
    if (string.IsNullOrWhiteSpace(kczt))
    {
        return;
    }
   <text>kczt</text>@(((Wms.EnumKczt)Enum.Parse(typeof(Wms.EnumKczt), kczt)).ToString("D"))
        
   }

@helper title(Wms.RackLocation loc)
    {
       @loc.Column<text>列</text>@loc.Level<text>层</text>  
       @loc.kczt<text> </text>
        if (loc.kczt == "包装后成品")
        {
            @loc.pz  <text> </text>
            @loc.gg <text> </text>
            @loc.xs
        }
    }
当前面的LOAD方法加载时,这个VIEW返回给前面的界面是一个HTML的字符。由前面的界面执行,但是这个字符又不是普通的。前面的JQUERY并不能直接取到里面的元素。


A界面需要对kczt_refresh.cshtml中的一些元素操作时,不能简单的使用$,需要使用(例如) $(".loc").live("click",function(){})

下面是一具体的代码:
 $(document).ready(function () {
          $(".loc").live("dblclick", function () {
              var title = $(this).attr("title");
              $.ajax({
                  type: "POST",
                  cache: false,
                  url: "/racklocations/details",
                  data: {
                      userCode: $(this).attr('userCode')
                  },
                  success: function (data) {
       
                  }
              });
          });

转载于:https://www.cnblogs.com/shenghaishiweini/p/3144393.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值