[英]change contents without reloading page
I got a page. 我有一页。 Its a key shop website.
它是一个关键商店的网站。 I want to make that when the customer clicks on the icon, for example
windows7
, it removes the other products beside it, and write its description and payment button. 我要确保当客户单击图标(例如
windows7
,它会删除旁边的其他产品,并写上其说明和付款按钮。 I already succeeded in not allowing the page to refresh, and only view the content. 我已经成功地不允许刷新页面,而只查看内容。 But the problem is the tab;
但是问题出在标签上。 I want to change it in the end of the page, and whenever I click on the icon for
windows7
it opens to me the page I want, but from the top. 我想在页面末尾进行更改,每当我单击
windows7
图标时,它就会从顶部打开我想要的页面。 I'am using the following code: 我正在使用以下代码:
<script>
$("div.haha").tabs("img.one > div", {effect: 'ajax'});
</script>
i just want it to change content and not to start from top 我只希望它更改内容而不是从头开始
<div id="haha">
<a href="product1.html"><img class="one" src="imgs/product1.png"></a>
<a href="#"><img class="two" src="imgs/product2.png"></a>
<a href="#"><img class="three" src="imgs/product 3.png"></a>
<a href="#"><img class="four" src="imgs/product4.png"></a>
</div>
Actually to access div
with "haha" id
you should use 实际上使用“ haha”
id
访问div
应该使用
$("div#haha")
selector. 选择。
I am changing the code, because I had this code on hand and it works pretty well from what I've seen and appears to fit all your needs. 我正在更改代码,因为我手头有此代码,并且根据我所看到的内容,它似乎可以很好地满足您的所有需求。
Javascript: (tested with jquery 1.9.1) Javascript :(已通过jquery 1.9.1测试)
<script type="text/javascript">
$(function(){
$("a[rel='haha']").click(function(e){
e.preventDefault();
/*
if uncomment the above line, html5 nonsupported browers won't change the url but will display the ajax content;
if commented, html5 nonsupported browers will reload the page to the specified link.
*/
//get the link location that was clicked
pageurl = $(this).attr('href');
//to get the ajax content and display in div with id 'haha'
$.ajax({url:pageurl+'?rel=haha',success: function(data){
$('#haha').html(data);
}});
//stop refreshing to the page given in
return false;
});
});
</script>
html example: html范例:
This is the code outside the div. This shouldnt be effected.
<br /><br />
Here are the links outside the div to show you how it works. IMG 2 will refresh page and change url because rel="haha" is missing from the url<br />
<a href="page2.php" rel="haha">IMG 1</a>
<a href="page2.php">IMG2 - NO REL</a>
<a href="../index.php">IMG3</a>
<a href="http://www.kygar.com/code/haha.php">RESET</a>
<br />
<br />
<br />
<div id="haha" style="border: 1px solid #ccc;">
<a href="../index.php" rel="haha">IMG1</a>
<a href="../services.php" rel="haha">IMG2</a>
<a href="http://www.gmail.com">IMG3 - NO REL</a>
</div>
Just know, any link you want to load into the div needs a rel="haha" (which can be changed to whatever you want to call it). 只需知道,要加载到div中的任何链接都需要一个rel =“ haha”(可以将其更改为您要调用的名称)。 If you want the page to load completely (like changing pages), just leave out the rel="haha" from the url.
如果您希望页面完全加载(例如更改页面),只需从URL中删除rel =“ haha”。
Demo of how the code works: http://kygar.com/code/haha.php 该代码如何工作的演示: http : //kygar.com/code/haha.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.