我想获取调用该函数的元素并将Google地图嵌入到目标div中。我尝试使用此代码但无法正常工作
function myfunction(currentElement){
var $elemId = $(this).attr("id");
$( ".$elemId" ).append( "<iframe frameborder="0" scrolling="no" marginheight="0"
marginwidth="0" src="https://maps.google.ch/maps?f=q&source=s_q&hl=de&geocode=&q=Bern&aq=&
sll=46.813187,8.22421&sspn=3.379772,8.453979&
ie=UTF8&hq=&hnear=Bern&t=m&z=12&
ll=46.947922,7.444608&output=embed&iwloc=near"></iframe>");
}
<div class='Flexible-container'>
<a href="#" id="showmap0" name="showmap0" onclick="myfunction(this);">show</a>
<div class='showmap0'></div>
</div>
答案 0 :(得分:1)
对于Id,我们使用#selectId
function myfunction(currentElement){
var $elemId = $(this).attr("id");
$( '#'+$elemId ).append( "<iframe frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.ch/maps?f=q&source=s_q&hl=de&geocode=&q=Bern&aq=& sll=46.813187,8.22421&sspn=3.379772,8.453979& ie=UTF8&hq=&hnear=Bern&t=m&z=12& ll=46.947922,7.444608&output=embed&iwloc=near"></iframe>" );
}
我希望这个帮助