简体   繁体   English

我应该在我的 jQuery 中使用哪个类?

[英]Which class should I use in my jQuery?

I am just develoing a Google chrome extension.我只是在开发一个谷歌浏览器扩展。

I am facing a problem or I'm confusing to get a class to work in my jQuery script.我遇到了一个问题,或者我很困惑让一个类在我的 jQuery 脚本中工作。 There are many classes for the textarea. textarea 有很多类。

Someone please tell me which one should I choose.有人请告诉我应该选择哪一个。

CSS CSS

._5t_y ._4_z2 .input, ._5t_y ._4zz- .input, ._5t_y.child_was_focused ._2yg .input

or或者

HTML HTML

class="uiTextareaAutogrow input autofocus _34z- mentionsTextarea textInput"

I just trying to add it in to this codes.我只是想将它添加到此代码中。 I tried ".input".我试过“.input”。 But it doesn't work for me.但这对我不起作用。

  $(document).ready(function() {
    $('.input').specialedit([':-)', ':-(', ';-)'],
                              { buttonWidth: 30,
                                buttonHeight: 30,
                                toolbarBgColor: '#ff0',
                                toolbarBorderColor: '#f00',
                                buttonBgColor: '#fff',
                                buttonBorderColor: '#f00',
                                buttonTextColor: '#f00' });
  });

如果您通过 .input 或 .uiTextareaAutogrow 访问它(知道这些是当前相同元素的现有类),您将在两种情况下都获得 textarea 但选择集可能会有所不同,因为类输入集的元素可能与uiTextareaAutogrow 类的元素集。

It does not actually differ what class to access, class groups HTML elements for a certain reason like formatting or display or any specific business functionality to be applied for this set.它实际上并没有区别要访问的classclass出于某种原因对 HTML 元素进行分组,例如格式化或显示或要应用于此集合的任何特定业务功能。 So the class selection gets you all the elements having this class.因此,类选择为您提供了具有此类的所有元素。

If you access it via .input or .uiTextareaAutogrow (knowing that these are the existing classes currently for the same element) you are gonna get your textarea in both cases but the selection set might differ since the elements of class input set might be different than the elements of the class uiTextareaAutogrow set.如果您通过.input.uiTextareaAutogrow访问它(知道这些是当前相同元素的现有类),您将在两种情况下都获得 textarea 但选择集可能会有所不同,因为类input集的元素可能与uiTextareaAutogrow类的元素集。

It is a good practice to create a specific class to be used for your plugin to make sure you select what you really need.创建一个用于插件的特定类以确保您选择真正需要的类是一个很好的做法。

For your current case, try to log the selection set console.log($('.input')) to make sure the selection is ok and you are getting the element you need, if so you shall check the function you have created to address the problem.对于您当前的情况,请尝试记录选择集console.log($('.input'))以确保选择正常并且您正在获取所需的元素,如果是这样,您应检查您创建的函数处理问题。

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

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