我有一个带有矩形子元素的 SVG。rect 子对象有一个onclick事件,该事件通过其 ID 获取另一个元素并更改其背景颜色。这适用于我桌面上的 Chrome 以及 Chrome 检查器中的 iOS 模拟器。但是,它不会在 iOS 设备上触发事件。
我可以在我的代码中进行哪些更改以在桌面和 iOS 设备上工作?我应该收听其他事件吗?
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" style="height: 200px; width: 200px; border: 4px dashed salmon;">
<rect x="25" y="25" height="50" width="50" style="cursor: pointer; fill: gold;" onclick="getElementById('box').style.backgroundColor = 'gold';"></rect>
</svg>
<div id="box" style="height: 200px; width: 200px; background-color: skyblue;"></div>
这是一个CodePen。