2017-04-20 96 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/

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

相關問題