首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >我可以在.setProperty中添加类似于属性的函数吗?

我可以在.setProperty中添加类似于属性的函数吗?
EN

Stack Overflow用户
提问于 2017-04-21 00:44:10
回答 2查看 1K关注 0票数 1

伙计们。我可以在jQuery .setProperty中使用类似于属性的函数吗?

代码语言:javascript
复制
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' );
    });
});
EN

回答 2

Stack Overflow用户

发布于 2017-04-21 01:57:18

在进一步的问题中,请向我们提供相关的CSS和HTML片段,以便对您的情况有一个完整的看法。

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

代码语言:javascript
复制
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/

注意:要进行计算,只需添加()即可运行。

票数 0
EN

Stack Overflow用户

发布于 2018-10-09 00:05:39

您可以尝试此语法。

代码语言:javascript
复制
this[0].style.setProperty( 'width', jQuery(jQuery('.content-wrapper').width() -  jQuery('.heading').width()), 'important' );

this[0].style.setProperty( 'border-color', 'red', 'important' );

代码语言:javascript
复制
this.attr( 'style', 'width: ' + jQuery(jQuery('.content-wrapper').width() -  jQuery('.heading').width()) + 'px !important' );

this.attr( 'style', 'border-color: red !important' );
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43525320

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档