jQuery CSS 选择器返回一个用两组双引号包裹的值 [英] jQuery CSS selector is returning a value wrapped in two sets of double quotes

查看:20
本文介绍了jQuery CSS 选择器返回一个用两组双引号包裹的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 CSS 属性进行非常简单的 jQuery 选择.奇怪的是,返回的值被包裹在两组双引号中?

I am doing a very simply jQuery select, using a CSS property. Oddly, the value is being returned wrapped in two sets of double quotes?

var font = $(this).css('font-family');

结果返回为:

font:""Jockey One""

推荐答案

包含空格的字体名称被引用,并且您的字体变量是一个字符串.因此是双引号.如果您想忽略引用字体名称中的引号,请执行以下操作:

font names containing a space are quoted and your font variable is a string. hence the double set of quotes. if you want to ignore the quotes in quoted font names, just do this:

var font = $(this).css('font-family');
font = font.replace(/["']/g, "");
console.log(font);

这篇关于jQuery CSS 选择器返回一个用两组双引号包裹的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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