伙计们。我可以在jQuery .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' );
});
});
发布于 2017-04-21 01:57:18
在进一步的问题中,请向我们提供相关的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/
注意:要进行计算,只需添加(
和)
即可运行。
发布于 2018-10-09 00:05:39
您可以尝试此语法。
this[0].style.setProperty( 'width', jQuery(jQuery('.content-wrapper').width() - jQuery('.heading').width()), 'important' );
this[0].style.setProperty( 'border-color', 'red', 'important' );
或
this.attr( 'style', 'width: ' + jQuery(jQuery('.content-wrapper').width() - jQuery('.heading').width()) + 'px !important' );
this.attr( 'style', 'border-color: red !important' );
https://stackoverflow.com/questions/43525320
复制相似问题