如何在jquery中为css样式指定变量 [英] How do I assign a variable to a css style in jquery

查看:130
本文介绍了如何在jquery中为css样式指定变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码更改样式的内容..

I used the following code for changing the content of a style..

$("#Button1").click(function () {

          var str="12";
          if ($('#additionalStyles').length)
          {
              $('#additionalStyles').remove();
          }
          else
          {
              $('head').append('<style id="additionalStyles">.noti_bubble:before{color: yellow; content:'"+str+"''';}</style>');


          }

          });





实际的css代码是......





The actual css code is ......

.noti_bubble:before{
    position:absolute;
    padding:1px 2px 1px 2px;
    background-color:red;
    content:"5";
    color:white;
    font-weight:bold;
    height : 11px;
    width: 15px;
}



jquery将颜色更改为黄色。但不要将内容从5改为12 ....

请帮助我....


The jquery changes the colour to yellow. but not change the content from 5 to 12....
pls help me....

推荐答案

#Button1)。click( function (){

var str = 12;
if
("#Button1").click(function () { var str="12"; if (


' #additionalStyles')。length)
{
('#additionalStyles').length) {


' #additionalStyles')。remove();
}
else
{
('#additionalStyles').remove(); } else {


这篇关于如何在jquery中为css样式指定变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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