2013-06-20 74 views
0

早上好,大家好,添加和删除使用jQuery

我新的ASP.NET & C#,所以请与我裸露的查询。所以基本上这是我想要做的:在btnzoomprevious & btnzoomnext被点击后追加一个名为?zoom = 1的查询。

<div id=zoomview class="view" style="left:100px;<%=isZoom?"":"display:none;" %>"> 
      <div class="side"> 
       <a id="btncloseview" class="btnview" style="left:-100px; top:60px;">close</a> 
       <a id="btnzoomprevious" class="btnzoomprevious" href="<%=ResolveClientUrl("~/" + gender + "/" + category + "/" + character + "/")%><%=prevproductName%><%=Request.Url.Query%>?zoom=1" style="margin:420px 0 0 -100px; display:<%=statusprev%>"></a> 
       <a id="btnzoomnext" class="btnzoomnext" href="<%=ResolveClientUrl("~/" + gender + "/" + category + "/" + character + "/")%><%=nextproductName%><%=Request.Url.Query%>?zoom=1 " style="margin:420px 0px 0 810px; display:<%=statusnext%>"></a> 
      </div> 
      <%if(!isZoom) {%> 
       <img src="<%=productImagesPath + prevproductImageZoom %>.jpg" id="mainImage" alt="Main Image" style="height:800px; width:800px;"/> 
       <img src="<%=productImagesPath + nextproductImageZoom %>.jpg" id="mainImage" alt="Main Image" style="height:800px; width:800px;"/> 
      <%}else {%>  
       <img data-src="<%=productImagesPath + productImageZoom %>.jpg" id="mainImage" alt="Main Image" style="height:800px; width:800px;"> 
      <%} %> 
     </div> 

我不能在ASP中使用的方法,因为?变焦= 1又再次追加。点击btncloseview后,我需要移除房间。有人可以指导我....先谢谢你。

回答

1

你想做什么?你只是试图追加查询到窗口中的网址?它可能是这样的:

<script type='text/javascript'> 
    $("#btnzoomprevious").on("click", function() { 
    if (window.location.href.indexOf('?zoom=1') == -1) { 
     window.location.href = window.location.href + '?zoom=1'; 
    } 
    }); 

    $("#btnzoomnext").on("click", function() { 
    if (window.location.href.indexOf('?zoom=1') == -1) { 
     window.location.href = window.location.href + '?zoom=1'; 
    } 
    }); 

    $("#btncloseview").on("click", function() { 
    if (window.location.href.indexOf('?zoom=1') != -1) { 
     window.location.href = window.location.href.substring(0, window.location.href.indexOf('?zoom=1')); 
    } 
    }); 
</script> 

但是,这会导致页面重新加载。如果你正在寻找一个解决方案,其中页面不会重新加载,你可以在这里找到更多的信息:

http://spoiledmilk.com/blog/html5-changing-the-browser-url-without-refreshing-page/

文章的短版本是,你可以实现以下功能:

window.history.pushState("object or string", "Title", "/new-url"); 

所以,你可以做这样的事情:

<script type='text/javascript'> 

    var urlPath = ''; 

    $("#btnzoomprevious").on("click", function() { 
     if (window.location.href.indexOf('?zoom=1') == -1) { 
      urlPath = window.location.href + '?zoom=1'; 
      window.history.pushState("","", urlPath); 
     } 
    }); 

    $("#btnzoomnext").on("click", function() { 
     if (window.location.href.indexOf('?zoom=1') == -1) { 
      urlPath = window.location.href + '?zoom=1'; 
      window.history.pushState("","", urlPath); 
     } 
    }); 

    $("#btncloseview").on("click", function() { 
     if (window.location.href.indexOf('?zoom=1') != -1) { 
      urlPath = window.location.href.substring(0, window.location.href.indexOf('?zoom=1')); 
      window.history.pushState("","", urlPath); 
     } 
    }); 

</script> 

你可以找到大卫默多克原来的职位有关更新URL没有reloa在此处查看更多信息:David's Post

祝你好运!

+0

谢谢你哟....设法弄清楚它...工作.... gbu .... :) –