当我直接指定它时,此代码段用于删除现有类,在添加新类之前(即'ratingBlock','ratingBlock1','ratingBlock2'等).但是当我在removeClass('[class ^ ="ratingBlock"]')中使用通配符选择器时,它不起作用.难道我做错了什么?谢谢.
<style type="text/css">
.ratingBlock {background:gold !important;}
.ratingBlock1, .ratingBlock2, .ratingBlock3, .ratingBlock4, .ratingBlock5 {background:LightGreen;}
</style>
<div class="test block ratingBlock">
Broken
<div><a href="#" class="ratingLink ratingNo-1">1+</a></div>
<div><a href="#" class="ratingLink ratingNo-2">2+</a></div>
<div><a href="#" class="ratingLink ratingNo-3">3+</a></div>
</div>
<script type="text/javascript">
// <![CDATA[
jQuery(document).ready(function(){
initRatingWorks();
});
function initRatingWorks() {
jQuery("a.ratingLink").bind('click', function() {
var star = jQuery(this);
var ratingBlock = star.parents('div.test.block');
var rating = star.attr('class').match(/\d+/);
if (ratingBlock.attr('class').indexOf('ratingBlock') !== -1) {
ratingBlock.removeClass('[class^="ratingBlock"]').addClass('ratingBlock' + rating);
}
else {
ratingBlock.addClass('ratingBlock' + rating);
}
return false;
});
}
// ]]>
</script>
Run Code Online (Sandbox Code Playgroud) 我有两个班级空着色.一旦我点击了彩色类,然后删除彩色类并添加空类.我再次点击它应该添加彩色类和remoce空类.但它没有用.
var color_click = false;
var select_color = "";
$( ".colored").on('click',function(e){
if(color_click != true){
color_click = true;
select_color = $(this).css('background-color');
$(this).removeClass("colored");
$(this).addClass( "empty");
$(this).css('background-color','')
}
});
$( ".empty").click(function(){
if(color_click == true){
color_click = false;
$(this).css('background-color',select_color);
$(this).addClass("colored");
$(this).removeClass( "empty");
}
});
Run Code Online (Sandbox Code Playgroud) 在过去的三天里,我一直在寻找解决我的问题的方法。我见过很多人和我有同样问题的人,但没有一种解决方案可以解决我的问题。所以我又回到了起点,我请求你们友好的人们的帮助!
我现在正在运行以下脚本,该脚本非常适合我:
$(".show_commentsandnotes_container").click(function () {
$('.commentsandnotes_bg').addClass('show');
$('.commentsandnotes_container').addClass('show');
});
$(".commentsandnotes_bg").click(function () {
$('.commentsandnotes_bg').removeClass('show');
$('.commentsandnotes_container').removeClass('show');
});
Run Code Online (Sandbox Code Playgroud)
我唯一无法开始工作的是元素的淡入和淡出。我尝试了很多解决方案,例如切换和显示/隐藏,但这最适合我。我需要的唯一简单的事情是将淡入淡出添加到脚本中(1000 毫秒),我只是无法解决这个问题。
有人能帮我吗?提前致谢。
我正在尝试根据匹配的列表项是否具有活动类来切换是否显示选项卡。我已经用 if 语句和 .hasClass 尝试了多种不同的方法,但无法让它按照我的意愿行事!任何帮助将不胜感激。
这是我的尝试之一的示例:
$( "#indexHero" ).onClick(function(){
$("#tabNo1.active"){
$( "#testID1, #testID2" ).addClass( "hideMe" );
$( "#testID3" ).removeClass( "hideMe" );
}
});
Run Code Online (Sandbox Code Playgroud) 由于一些奇怪的原因,我的网站正在复制一个div元素.在我试图找出它被复制的原因之前,我正在寻找一种暂时隐藏重复的方法div.
我试过以下脚本:
$(document).ready(function() {
$('.ms-account-wrapper').eq(1).remove();
});
Run Code Online (Sandbox Code Playgroud)
HTML:
<div class="ms-account-wrapper">1</div>
<div class="ms-account-wrapper">2</div> <---want to remove this one
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
非常感谢
马克斯
我想禁用 dataTable API 中的排序属性。我使用 bsort:false 禁用所有列的排序。
这很好用,但第一列仍然显示排序图标。为什么 ?
$("#reportgrid").DataTable({
"order": [],"bSort" : false,
"iDisplayLength": 10,
"sDom": '<"top">rt<"bottom"lp><"clear">',
});
Run Code Online (Sandbox Code Playgroud)
我将此代码用于数据表。
这是我的网格的快照。其中第一列具有 sorting_asc 的 css,但我已经禁用排序。
那么,如何从第一列中删除排序图标?
我有一个表,所有行都有一个div的单元格,其动态生成的id格式为btn-insertidhere.
当选择表格行时,我想选择此div id,然后删除一个类并将其更改为另一个类.这取决于我想要将按钮图像从添加符号更改为删除符号(单击时).
javascript代码:
$('*[class^=day] tbody tr[id^=band]').live('click', function() {
var DivId = $(this).find('div.add').attr('id');
alert(DivId);
$('DivId').removeClass('add').addClass('del');
$('table#fri_myTimes tbody').append($(this)).fadeIn(1000);
return false;
});
Run Code Online (Sandbox Code Playgroud)
这是动态生成的代码的html片段:
<tr id="band-Modest-Mouse">
<td>Modest Mouse</td>
<td>15:25:00</td>
<td>16:10:00</td>
<td>45</td>
<td><div id="btn-Modest-Mouse" class="add"> </div></td>
</tr>
Run Code Online (Sandbox Code Playgroud)
如您所见,我想将"添加"类更改为删除"类".表格中的所有表格行都是这样生成的,因此您可以看到我已经选择了通配符方法,这似乎有效,因为显示的警报显示了正确的div id.我只需要改变课程!
谢谢!
<div>
<input type="text" placeholder="#" class="error">
<input type="text" placeholder="#" class="error">
</div>
var copylast = $('div').html();
Run Code Online (Sandbox Code Playgroud)
我正在尝试复制DIV但是从copylast变量中删除了类错误(我需要将类保留在原始div中.)
我试过一个字符串替换var copylast = copylast.replace('class="error"', ''); 但它只删除了第一个实例,加上看起来很俗气.removeClass('error')如果可能的话,我更愿意使用.
这是HTML:
<a id="docLocked" title="Unlock this document" style="text-decoration: none; cursor: pointer;"><span class="iconfa-lock"></span></a>
Run Code Online (Sandbox Code Playgroud)
单击"图标"时,我需要它删除span元素的类,然后添加另一个类.
这是我的,但它不起作用:
jQuery('#docLocked').click(function () {
jQuery(this).closest('span').removeClass('iconfa-lock');
jQuery(this).closest('span').addClass('iconfa-unlock');
});
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?
请帮助我如何从 WordPress 自定义菜单中的菜单 ul 中删除 id。我无法从 ul 标签中的 id 中删除 id 我的代码是
我想删除 id="menu-primary-menu" 提前致谢
removeclass ×10
jquery ×9
addclass ×5
css ×2
html ×2
javascript ×2
datatable ×1
duplicates ×1
dynamic ×1
fade ×1
html-lists ×1
menu ×1
onclick ×1
selector ×1
sorting ×1
wildcard ×1