jQuery 中的 attr() 是否强制小写? [英] Does the attr() in jQuery force lowercase?

查看:24
本文介绍了jQuery 中的 attr() 是否强制小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试操作如下所示的 svg 'viewBox' 属性:

I'm trying to manipulate the svg 'viewBox' attribute which looks something like this:

<svg viewBox="0 0 100 200" width="100" ...> ... </svg>

使用

$("svg").attr("viewBox","...");

然而,这会在名为viewbox"的元素中创建一个新属性.注意小写而不是预期的驼峰式.我应该使用其他功能吗?

However, this creates a new attribute in the element called "viewbox". Notice the lowercase instead of intended camelCase. Is there another function I should be using?

推荐答案

我能够使用纯 javascript 来获取元素并通过使用设置属性

I was able to use pure javascript to get the element and set the attribute by using

var svg = document.getElementsByTagName("svg")[0];

svg.setAttribute("viewBox","...");

这篇关于jQuery 中的 attr() 是否强制小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆