简体   繁体   English

在jquery中创建一个插件以分别设置每个元素的样式

[英]Create a plugin in jquery to style each element separately

I am creating my first plugin in jquery. 我在jquery中创建我的第一个插件。 I have went through the basics and now I have started to work on it. 我已经学习了基础知识,现在我已经开始研究它。 My approach is simple. 我的方法很简单。 I want to allow users to style each element differently. 我想允许用户为每个元素设置不同的样式。

Eg 例如

     $('#form').style({                         
      inputelement:{
         border:'red',
         color:'#dcdcdc'
      }
  });

Goal for this plugin is to allow users to style elements independently 该插件的目标是允许用户独立设置元素样式

inputelement will be the id of the element of my form. inputelement将是表单元素的ID。 I want to apply styles to elements of a form. 我想将样式应用于表单的元素。

I know it can be easily done using css, but I want to experiment with plugins in jquery. 我知道可以使用CSS轻松完成,但是我想尝试使用jquery中的插件。

I think this is some advanced concept which I am thinking of, but I need some sort of output like this. 我认为这是我正在考虑的一些高级概念,但是我需要这样的输出。

As some of the commentators have mentioned, you are re-inventing the wheel here. 正如一些评论员所提到的,您正在这里重新发明轮子。 You can achieve the same thing by this. 这样您可以实现相同的目的。

$('#form').children('input').css({..})
.children('label').css({..});

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

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