Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.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
jQuery.css()函数不能处理变量_Jquery_Html_Css - Fatal编程技术网

jQuery.css()函数不能处理变量

jQuery.css()函数不能处理变量,jquery,html,css,Jquery,Html,Css,我正在尝试创建一个函数来根据用户输入更新CSS,并且除了CSS属性参数外,它还可以正常工作 $document.readyfunction{ $'input'.Blur函数{ var inputName=$this.attrname; UpdatecsInputName,'按钮样式一','背景色'; } //更新CSS的函数 函数updateCSSpInputNameAttribute、pElementClass、pCssProperty{ 变量inputName='[name='+pInpu

我正在尝试创建一个函数来根据用户输入更新CSS,并且除了CSS属性参数外,它还可以正常工作

$document.readyfunction{ $'input'.Blur函数{ var inputName=$this.attrname; UpdatecsInputName,'按钮样式一','背景色'; } //更新CSS的函数 函数updateCSSpInputNameAttribute、pElementClass、pCssProperty{ 变量inputName='[name='+pInputNameAttribute+']', elementClass='.'+pElementClass, inputValue=$inputName.val; $elementClass.css{ pCssProperty:inputValue }; } };
通过先创建对象,然后分配密钥,可以访问css对象的pCssProperty内容:

var cssObj = {};
cssObj[pCssProperty] = inputValue;
$(elementClass).css(cssObj);
…或使用此ES6速记来执行相同的操作:

$(elementClass).css({[pCssProperty]: inputValue})
$document.readyfunction{ $'input'.Blur函数{ var inputName=$this.attrname; UpdatecsInputName,'按钮样式一','背景色'; } //更新CSS的函数 函数updateCSSpInputNameAttribute、pElementClass、pCssProperty{ 变量inputName='[name='+pInputNameAttribute+']', elementClass='.'+pElementClass, inputValue=$inputName.val; $elementClass.css{ [pCssProperty]:输入值 }; } };
当您定义一个对象时,比如jQuery的.css方法作为参数的对象,您可以使用不带引号的属性名。变量通常不会在冒号的左侧进行插值。因此,您的代码试图设置一个CSS属性,该属性的字面名称为pCssProperty。+1我知道发生了什么,但我不知道您可以将一个变量放在方括号中以获取对象定义中的值。