【问题标题】:How to add more value to existing class (wordpress)?如何为现有类(wordpress)增加更多价值?
【发布时间】:2021-05-23 00:23:56
【问题描述】:

我需要将“wsqmylogin”添加到现有课程中。
我尝试了以下代码,但它们都没有添加它。
请告诉我如何解决这个问题?

现有代码(由插件 YITH 创建):

<form id="yith-ywraq-default-form">
     <p class="form-row " id="message_field" data-priority="">
          <textarea name="message" class="input-text " id="message" placeholder=""></textarea>
    </p>
</form>


我试过了:

jQuery('#yith-ywraq-default-form #message_field textarea[class="input-text"]').each(function()
{ this.setAttribute('class', 'wsqmylogin'); });

jQuery("#yith-ywraq-default-form #message_field textarea").prop("classs","wsqmylogin");

jQuery("#yith-ywraq-default-form #message_field  .input-text").prop("wsqmylogin")

谢谢。

【问题讨论】:

  • 在控制台上运行jQuery('#yith-ywraq-default-form #message_field textarea[class="input-text"]').length?你找到标记了吗?
  • 您好:感谢您的评论。我试过了,它显示 1。你能告诉我我必须采取什么步骤吗?
  • 见下面的答案:)

标签: jquery wordpress class add


【解决方案1】:
  1. 不要在你的类名中使用-
  2. id 必须是唯一的,因此在遍历每个文本框时不要使用 id。使用class
  3. 如果您只有 1 个textarea,则无需迭代,只需捕获 DOM 元素并应用您的 css。
  4. setAttribute 替换你以前的整个课程,所以如果你想添加新课程,只需使用 addClass

jQuery('#yith-ywraq-default-form .form-row textarea[class="inputtext"]').each(function() {
  this.setAttribute('class', 'inputtext wsqmylogin');
  //jQuery(this).addClass('inputtext wsqmylogin');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="yith-ywraq-default-form">
  <p class="form-row" id="message_field" data-priority="">
    <textarea name="message" class="inputtext" id="message" placeholder=""></textarea>
  </p>
</form>

【讨论】:

  • 嗨 Shree:哦,我明白了,非常感谢您的解释和帮助 :) ...现有代码是由插件创建的。我是新手,所以我没有构建代码的技能嘿嘿......
猜你喜欢
  • 2022-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-22
  • 1970-01-01
  • 2018-10-18
相关资源
最近更新 更多