将类名更改为空名称。

huangapple go评论101阅读模式
英文:

Change A Class Name to a empty name

问题

I want to change the Class name when I enter the Web

Here is the Html :

<div class="row innerbodypanel">
    <form name="AGX" id="AGX" action="" method="post" autocomplete="off">
</div>

I want to change the Class (row innerbodypanel) to empty like Class=""

英文:

I'm noob and I need help.
I want to change the Class name when I enter the Web

Here is the Html :

&lt;div class=&quot;row innerbodypanel&quot;&gt;
    &lt;form name=&quot;AGX&quot; id=&quot;AGX&quot; action=&quot;&quot; method=&quot;post&quot; autocomplete=&quot;off&quot;&gt;
&lt;/div&gt;

I want to change the Class (row innerbodypanel) to a empty like Class=""

答案1

得分: 1

&lt;!-- 开始代码片段: js 隐藏: false 控制台: false Babel: false --&gt;

&lt;!-- 语言: lang-js --&gt;

    使用 jQuery 的 removeClass 方法
    $(&quot;.innerbodypanel&quot;).removeClass(&quot;row innerbodypanel&quot;)

&lt;!-- 语言: lang-html --&gt;

    &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js&quot;&gt;&lt;/script&gt;
    &lt;div class=&quot;row innerbodypanel&quot;&gt;
    &lt;form name=&quot;AGX&quot; id=&quot;AGX&quot; action=&quot;&quot; method=&quot;post&quot; autocomplete=&quot;off&quot;&gt;

&lt;!-- 结束代码片段 --&gt;
英文:

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-js -->

use jQuery removeClass
$(&quot;.innerbodypanel&quot;).removeClass(&quot;row innerbodypanel&quot;)

<!-- language: lang-html -->

&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;div class=&quot;row innerbodypanel&quot;&gt;
&lt;form name=&quot;AGX&quot; id=&quot;AGX&quot; action=&quot;&quot; method=&quot;post&quot; autocomplete=&quot;off&quot;&gt;

<!-- end snippet -->

答案2

得分: 0

你可以使用className属性将其更改为空字符串(&#39;&#39;)。

document.querySelector('.btn').onclick = () => {
  document.querySelector('.row.innerbodypanel').className = '';
}
.row {
  background-color: red;
}

.innerbodypanel {
  color: white;
  font-weight: bold;
}
<div class="row innerbodypanel">test!</div>
<form name="AGX" id="AGX" action="" method="post" autocomplete="off"></form>
<button class="btn">click me!</button>
英文:

You could use the className property to change it to an empty string (&#39;&#39;)

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

document.querySelector(&#39;.btn&#39;).onclick = () =&gt; {
  document.querySelector(&#39;.row.innerbodypanel&#39;).className = &#39;&#39;;
}

<!-- language: lang-css -->

.row {
  background-color: red;
}

.innerbodypanel {
  color: white;
  font-weight: bold;
}

<!-- language: lang-html -->

&lt;div class=&quot;row innerbodypanel&quot;&gt;test!&lt;/div&gt;
&lt;form name=&quot;AGX&quot; id=&quot;AGX&quot; action=&quot;&quot; method=&quot;post&quot; autocomplete=&quot;off&quot;&gt;&lt;/form&gt;
&lt;button class=&quot;btn&quot;&gt;click me !&lt;/button&gt;

<!-- end snippet -->

答案3

得分: 0

以下是翻译好的内容:

尝试像这样

    <div id="A" class="row innerbodypanel">
       <form name="AGX" id="AGX" action="" method="post" autocomplete="off">
    </div>

    $("#A").removeClass("innerbodypanel")
英文:

try like this

&lt;div id=&quot;A&quot; class=&quot;row innerbodypanel&quot;&gt;
   &lt;form name=&quot;AGX&quot; id=&quot;AGX&quot; action=&quot;&quot; method=&quot;post&quot; autocomplete=&quot;off&quot;&gt;
&lt;/div&gt;

$(&quot;#A&quot;).removeClass(&quot;innerbodypanel&quot;)

答案4

得分: 0

$(document).ready(() => {
$("div").removeClass("row innerbodypanel");
});

这将在整个页面加载完成后移除该类。因此,在div元素加载之前,不会执行removeClass函数。
此外,您可能需要为该div添加一个id,因为“div”选择器非常通用。

英文:
$(document).ready(() =&gt;
{
    $(&quot;div&quot;).removeClass(&quot;row innerbodypanel&quot;);
});

This will remove the class when the entire page is loaded. Thus, there is no danger that the removeClass function will be executed before the div element is loaded.
Also you will maybe need an id for the div because the "div" selector is very generic.

huangapple
  • 本文由 发表于 2020年1月6日 22:43:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/59614057.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定