简体   繁体   English

如何在按钮单击上添加自定义CSS?

[英]How to add custom CSS on button click?

I have a button that has some predefined CSS. 我有一个带有一些预定义CSS的按钮。 With this button i have created an action button and a textarea. 使用此按钮,我创建了一个动作按钮和一个文本区域。

Whenever i write some CSS in textarea then it should be added to existing button's CSS when submitting this CSS by action button. 每当我在textarea中编写一些CSS时,在通过操作按钮提交此CSS时,都应将其添加到现有按钮的CSS中。

I tried this- 我尝试了这个

jQuery- jQuery-

$(function(){
    $('.add').click(function(){
      var custom=$('.textarea').val();
        $('.button').css(custom);

    });
});

But it doesn't seem to be working, How can i do this? 但这似乎不起作用,我该怎么做?

Is iframe Needed here? 这里需要iframe吗?

Fiddle 小提琴

You could try something like: 您可以尝试类似:

$('.button').attr("style", custom);

jsFiddle 的jsfiddle

Maybe try this 也许试试这个

   $(function(){
        $('.add').click(function(){
          var custom=$('.textarea').val().split(',');        
             $('.button').css(custom[0],custom[1]);
        });
    });

pass in background,red in text area background,red传递background,red在文本区域中为background,red

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM