Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jQuery获取webkit筛选器属性的数值_Javascript_Jquery_Css - Fatal编程技术网

Javascript 使用jQuery获取webkit筛选器属性的数值

Javascript 使用jQuery获取webkit筛选器属性的数值,javascript,jquery,css,Javascript,Jquery,Css,返回: $(".content").css("-webkit-filter") 如何仅获取该值:0.46?您可以使用regex(): RegExp取自此小提琴 "opacity(0.46) grayscale(0.7)" var cssStyle = $(".content").css("-webkit-filter"); var regExp = /opacity\(([^)]+)\)/; var matches = regExp.exec(cssStyle); console.log

返回:

$(".content").css("-webkit-filter")
如何仅获取该值:0.46?

您可以使用regex():

RegExp取自此小提琴

"opacity(0.46) grayscale(0.7)"
var cssStyle = $(".content").css("-webkit-filter");
var regExp = /opacity\(([^)]+)\)/;
var matches = regExp.exec(cssStyle);

console.log(matches[1]);
var regExp = /\(([^)]+)\)/;
var str = regExp.exec("opacity(0.46) grayscale(0.7)");
var modified = str[0].substring(1).slice(0, -1);
console.log(modified);
$(".content").css('opacity')