Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
我想问一下 - 通过Javascript - 更改单选按钮的标签
innerText
(参见下面的代码), 同时不擦除里面的输入标签 。 标签innerText在这里意味着“ Button-Label-X ”。我试图通过
document.getElementsByClassName("radio-label")
元素来诊断标签样式,包括
- textContent:“Button-Label-X”
- innerText:“Button-Label-X”
- outerText:“Button-Label-X”
然后为它们分配新的字符串值(例如“Button-Label-Y”)。 然而,所有这些方式导致相同的结果:输入消失,只剩下新值。 有人有任何想法吗?
<div class="radio"> <label class="radio-label"><input type="radio" name="optradio"> Button-Label-X </label> </div>
当然,我可以通过将输入标签放在标签之外来解决问题,然后一切都解决了。 但是,对于这种情况,我必须为输入设置
id
,为标签设置“for:id”。 对于05按钮而不是01按钮的情况来说,它变得繁琐。I would like to ask how - by Javascript - to change the label
innerText
of radio buttons (see code below) while not wiping out the input tag inside. Label innerText here means "Button-Label-X".I've tried to diagnose the label style via elements of
document.getElementsByClassName("radio-label")
, including
- textContent: "Button-Label-X"
- innerText :"Button-Label-X"
- outerText :"Button-Label-X"
then assigned new string value (ex. "Button-Label-Y") to them. However, all those ways lead to the same result: the input disappeared, only new value left. Anyone has any idea here?
<div class="radio"> <label class="radio-label"><input type="radio" name="optradio"> Button-Label-X </label> </div>
Of course, I could do the way around by putting input tag outside of label, then everything is solved. But, for that case, I must set
id
for input and "for:id" for label. And it becomes tedious work for the case of 05 buttons instead of 01 one.
原文:https://stackoverflow.com/questions/45695278
最满意答案
你最好的答案可能是在一个类中有动画序列,并使用jQuery来添加类。 例如CSS
@keyframes slide-left { 0% { -webkit-transform: translateX(-200%); } 70% { -webkit-transform: translateX(2%); } 100% { -webkit-transform: translateX(0); } } .slide-it { animation: slide-left 0.9s ease-in-out 1s both; }
然后是JS
$("#button").on('click', show_function); function show_function() { $(".graph").fadeIn("slow"); $('.bar-container').addClass('slide-it'); }
Your best answer is likely to be have the animation sequence in a class, and use jQuery to add the class. E.g. CSS
@keyframes slide-left { 0% { -webkit-transform: translateX(-200%); } 70% { -webkit-transform: translateX(2%); } 100% { -webkit-transform: translateX(0); } } .slide-it { animation: slide-left 0.9s ease-in-out 1s both; }
And then JS
$("#button").on('click', show_function); function show_function() { $(".graph").fadeIn("slow"); $('.bar-container').addClass('slide-it'); }
相关问答
更多-
尝试在我的jquery幻灯片中添加额外的标题动画(Trying to add an additional title animation to my jquery slideshow)[2024-01-30]
插件的jQuery代码,第一个剪断你附加的,正在寻找每个元素( h2和h3 )并一个接一个地动画它们。 只需为h4添加相同的代码,然后将所需的任何更改应用于像素值。 // titles animation $nextSlide.find('div.ei-title > h2') .css( 'margin-right', 50 + 'px' ) .stop() .delay( this.opt ... -
添加动画到jQuery(Add animation to jQuery)[2022-05-30]
你想要的是在所有jQuery插件中完成的 。 我们的想法是将您的函数添加到jQuery的prototype中,其名称为$.fn 。 你这样做: $.fn.myFadeOut = function(){ return this.animate({opacity: '0'}, 200, function() { $(this).animate({height: '0'}, 200, function() { $(this).remove(); }) ... -
你最好的答案可能是在一个类中有动画序列,并使用jQuery来添加类。 例如CSS @keyframes slide-left { 0% { -webkit-transform: translateX(-200%); } 70% { -webkit-transform: translateX(2%); } 100% { -webkit-transform: translateX(0); } } .slide-it { animation: slide-l ...
-
你在jQuery中添加了uno类,但你没有.uno的相应CSS规则。 我添加了一个和最小的样式来显示这个工作: $(document).ready(function() { $(".animar").click(function() { $('#img4').addClass('uno'); }); }); #img4 { position: absolute; top: 30px; } .uno { animation-name: uno; anim ...
-
更新了您的代码。 添加了悬停功能,否则动画只能运行一次。 $('#babies').hover( function(){ $('#needle').addClass('animation-babies') }, function(){ $('#needle').removeClass('animation-babies') } ); $('#kids').hover( function(){ $('#needle').addClass('animation-kids') }, ...
-
jQuery网站上的这个例子可能会帮助解决这个问题 - 在同一个元素上制作几个动画。 该示例显示了使用队列一次或依次对动画进行排序: http://api.jquery.com/animate/#example-2 还要注意MLM在上面对几个元素排队动画的评论: jQuery中的非嵌套动画序列? This example on the jQuery site may help some on this issue - where several animations are made on the same ...
-
jquery为动画添加延迟(jquery add delay to animation)[2022-04-30]
我认为您需要在第二个块中将调用链接在一起,或者它们以异步方式运行: $("#test").hover(function() { $(this).css({'z-index' : '10'}); $(this).addClass("hover").stop() .animate({ height: '60px' }, 1500); } , function() { $(this).css({'z-index' : '0' ... -
想要这样的东西? 这是没有JavaScript我能做的最好的! 虽然我很开心。 input[type=checkbox] { opacity: 0; } input[type=checkbox] + label{ width:100px; height:40px; border:thin solid black; display:block; } input[type=checkbox] + label:before { content: "Run Bab ...
-
您还可以使用SMIL动画语法而不是CSS动画。 无可否认,这有点不能在Microsoft浏览器(IE和Edge)中运行。 var animation = document.getElementById("dash") function showSVG(){ animation.beginElement(); } svg{ position:relative; width:100 ...
-
addClass()不是jQuery动画队列的一部分,因此不受delay()影响。 正确使用setTimeout应该有效: DEMO var addClassToEl = function($el) { $el.addClass('animated fadeInDown'); }; $('.row-assets .asset').each(function(i, el) { setTimeout(function() {addClassToEl($(el))}, i++ * 500); } ...