Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.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 设置需要变量时使用.before()添加的元素的样式_Jquery_Html_Css - Fatal编程技术网

Jquery 设置需要变量时使用.before()添加的元素的样式

Jquery 设置需要变量时使用.before()添加的元素的样式,jquery,html,css,Jquery,Html,Css,我正在使用jQuery函数创建一个元素。在此之前: d.children().first().before("<div class='test-div'><span class='test-span'>" + text + "</span></div>") 但是,由于.before函数需要使用双引号,因此不起作用。我尝试在之后.之前使用.style,但我得到: Uncaught TypeError: d.children(...).first(.

我正在使用jQuery函数创建一个元素。在此之前:

d.children().first().before("<div class='test-div'><span class='test-span'>" + text + "</span></div>")
但是,由于.before函数需要使用双引号,因此不起作用。我尝试在之后.之前使用.style,但我得到:

Uncaught TypeError: d.children(...).first(...).before(...).style is not a function
是否有一个解决方案是我所缺少的,或者我需要以其他方式应用该样式


其他人认为这是一个重复的问题,但相关的问题本质上是完全不同的。我不需要逃避一句话。基本上,我需要在两组中使用第三组引号

我不完全明白问题出在哪里

d.children().first().before("<div class='test-div'><span class='test-span' style='" + (left + leftOffset) + "'>" + text + "</span></div>")

应该可以正常工作。

请查看可能的“不完全”副本。我不需要使用转义字符\style='left:+leftOffset+'最终成为我所需要的,我认为我已经尝试过了,但显然没有。非常感谢。
d.children().first().before("<div class='test-div'><span class='test-span' style='" + (left + leftOffset) + "'>" + text + "</span></div>")