2017-04-20 99 views
1

伙计。我可以在jQuery .setProperty中使用类似于属性的函数吗?我可以在.setProperty中添加像属性一样的功能吗?

jQuery(document).ready(function(){ 
jQuery(".content-wrapper").mouseenter(function(){ 
    jQuery(this).find('.separator-content-box').each(function(){ 
     this.style.setProperty('width', jQuery(jQuery('.content-wrapper').width() - jQuery('.heading').width()), 'important'); 
     this.style.setProperty('border-color', 'red', 'important'); 
    }); 
}); 
+0

是的!但在这个“this.style.setProperty('width',jQuery(jQuery('。content-wrapper')。width() - jQuery('。heading')。width())''中有一个额外的jQuery,重要的');“ –

回答

0

在进一步的问题中,请提供与您的案例有关的CSS和HTML片段。

在jQuery中,我推荐使用'css()'函数将内联样式添加到元素。你的代码应该是这样的:

jQuery(document).ready(function(){ 
    jQuery(".content-wrapper").mouseenter(function(){ 
     jQuery(this).find('.separator-content-box').each(function(){ 
      jQuery(this).css('width',(jQuery('.content-wrapper').width() - jQuery('.heading').width())); 
      jQuery(this).css('border-color','red'); 
     }); 
    }); 
}); 

我不知道你的HTML/CSS结构,但有一个测试,我做了尝试:https://jsfiddle.net/97fjbp12/

注:要做到,你只需要添加(计算, )使其工作。

相关问题