我在使用我的 SVG 中内置的锚元素时遇到了很多麻烦(显示为<object>)。我正在尝试使用 jQuery 将我的对象中的锚点元素作为目标,以便在单击时切换其各自的内容。
如果您看一下我的示例,我的 SVG 中内置了 3 个链接(它们的绿色阴影比其他的更浅)。我使用 InkScape 创建我的 SVG 图像,并且在链接的浅绿色区域上只是 href 属性分别等于“#operable-shades”、“#gutters-downspouts”和“#gable-pediments”的形状。
当我的 SVG 在我的页面上很好地显示(使用标签<object>)时,当将鼠标悬停在我创建的链接上时,我得到原始对象数据 URL,并在其末尾附加了我指定的锚点(例如“https://example.com” /wp-content/uploads/GHB_Interface-v0.1.svg#gable-pediments') 当我期望它是'https://example.com/#gable-pediments'。
<script type="text/javascript">
jQuery(document).ready(function($) {
$('.ghb_toggle').hide()
$('a[href^="#"]').on('click', function(event) {
var target = $(this).attr('href');
$(target).toggle();
});
});
</script>
.ghb_toggle {
display:none;
}
<object type="image/svg+xml" data="https://example.com/wp-content/uploads/test.svg" width="500" height="400"></object>
<div id="gable-pediments" class="ghb_toggle">
<p>Content 1</p>
</div>
<div id="gutters-downspouts" class="ghb_toggle">
<p>Content 2</p>
</div>
<div id="operable-shades" class="ghb_toggle">
<p>Content 3</p>
</div>
我怎样才能修改我的 jQuery 以便能够成功地与我内部的锚元素交互<object>以隐藏/显示具有唯一标识符的相应内容?
吃鸡游戏
一只名叫tom的猫
随时随地看视频慕课网APP
相关分类