我有这件事我想做。我有一张地图的主要图片,在该地图中有区域。这些区域上有热点,因此您可以单击它们,它将仅用区域替换整个地图。 (只是一个简单的div
交换)。
我需要它作为div
,因为在此div
我列出了热点。
我需要总共4 div
个。
如果有人能帮助我那会很棒!
因此,表格中列出的链接需要在单独的div
中替换图像。
<tr class="thumb"></tr>
<td>All Regions (shows main map) (link)</td>
</tr>
<tr class="thumb"></tr>
<td>Northern Region (link)</td>
</tr>
<tr class="thumb"></tr>
<td>Southern Region (link)</td>
</tr>
<tr class="thumb"></tr>
<td>Eastern Region (link)</td>
</tr>
</table>
<div>All Regions image</div>
<div>northern image</div>
<div>southern image</div>
<div>Eastern image</div>
我不允许发布图片,因为我没有足够的分数,所以我知道图片链接不起作用。
答案 0 :(得分:55)
您可以使用.replaceWith()
$(function() {
$(".region").click(function(e) {
e.preventDefault();
var content = $(this).html();
$('#map').replaceWith('<div class="region">' + content + '</div>');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="map">
<div class="region"><a href="link1">region1</a></div>
<div class="region"><a href="link2">region2</a></div>
<div class="region"><a href="link3">region3</a></div>
</div>
答案 1 :(得分:12)
HTML
<div id="replaceMe">i need to be replaced</div>
<div id="iamReplacement">i am replacement</div>
<强>的JavaScript 强>
jQuery('#replaceMe').replaceWith(jQuery('#iamReplacement'));
答案 2 :(得分:1)
这should可以帮助您
HTML
<!-- pretty much i just need to click a link within the regions table and it changes to the neccesary div. -->
<table>
<tr class="thumb"></tr>
<td><a href="#" class="showall">All Regions</a> (shows main map) (link)</td>
<tr class="thumb"></tr>
<td>Northern Region (link)</td>
</tr>
<tr class="thumb"></tr>
<td>Southern Region (link)</td>
</tr>
<tr class="thumb"></tr>
<td>Eastern Region (link)</td>
</tr>
</table>
<br />
<div id="mainmapplace">
<div id="mainmap">
All Regions image
</div>
</div>
<div id="region">
<div class="replace">northern image</div>
<div class="replace">southern image</div>
<div class="replace">Eastern image</div>
</div>
的JavaScript
var originalmap;
var flag = false;
$(function (){
$(".replace").click(function(){
flag = true;
originalmap = $('#mainmap');
$('#mainmap').replaceWith($(this));
});
$('.showall').click(
function(){
if(flag == true){
$('#region').append($('#mainmapplace .replace'));
$('#mainmapplace').children().remove();
$('#mainmapplace').append($(originalmap));
//$('#mapplace').append();
}
}
)
})
CSS
#mainmapplace{
width: 100px;
height: 100px;
background: red;
}
#region div{
width: 100px;
height: 100px;
background: blue;
margin: 10px 0 0 0;
}