【发布时间】:2019-01-25 05:03:28
【问题描述】:
我遇到了一个问题,我想通过 jQuery 在 SVG 中删除/更改属性 viewBox(注意大写“B”)。
我的代码是:
$('svg').removeAttr('viewBox').attr('viewBox', '0 0 963 630');
但是出现的是这个viewbox(带有小写的“b”)为了让我正在做的工作,它需要是一个大写的“B”。如何添加区分大小写的属性?
提前致谢!
【问题讨论】:
-
不要使用 jQuery。使用 DOM。
-
Here's an answer from 2015 about jquery doing toLowerCase and not caring, but it has a workaround. 实际上上面的答案可能有效,即更新 2 或
$("svg")[0].setAttribute("viewBox", "0 0 166 361"); -
@HereticMonkey 那么你是说你可以强制 HTML 属性使用 vanilla JS 区分大小写吗?
-
@jom 是的,例如,请参阅 this fiddle。
-
@HereticMonkey - 有效。做到了:
document.getElementsByTagName("svg")[0].setAttribute("viewBox", "0 0 963 630");。 :)
标签: javascript jquery attributes case-sensitive