【问题标题】:How to set js variable in style tag [duplicate]如何在样式标签中设置js变量[重复]
【发布时间】:2023-03-16 12:03:01
【问题描述】:

我已经在js文件中编写了这段代码。但是需要在样式标签内使用user_id js 变量来获取内容。该怎么做?

$('head').append('<style>.video-js:before{content: "user_id";}</style>');

【问题讨论】:

  • 只需像这样使用连接:$('head').append('&lt;style&gt;.video-js:before{content: "' + user_id + '";}&lt;/style&gt;');
  • 或使用模板文字 (developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…) 如下: $('head').append(``);
  • 是的,它奏效了。谢谢。

标签: javascript php jquery css


【解决方案1】:

问题就这样解决了。可能对某人有帮助。

var content = '<style>.video-js:before{content: "'+user_id+'";}</style>';
$('head').append(content);

【讨论】:

    猜你喜欢
    • 2018-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-13
    • 2016-04-13
    • 2019-12-05
    • 2019-02-10
    • 1970-01-01
    相关资源
    最近更新 更多