2013-06-20 104 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 .... :) –