2017-11-11 147 views
1

你好,我有一個元素兩個CSS樣式屬性樣式中的第一和jQuery的屬性CSS中的第二個,我想採取的第一個 這樣的:採取CSS的第一要素


$(document).ready(function() { 
 

 
\t jQuery(".iview-group-19").iView({ 
 
\t \t captionSpeed: 500, // speed to show caption 
 
\t \t captionOpacity: 1, // caption opacity 
 
\t \t captionEasing: 'easeInOutSine', // caption transition easing effect, use JQuery Easings effect 
 
\t \t customWidth: 1920, 
 
\t \t customHtmlBullet: false, 
 
\t \t rtl: false, 
 
\t \t height:500, 
 

 
    }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<div class="iview iview-group-19" id="slide-height" style="height: 351px;">

回答

1

首先,您需要檢查元素中是否存在樣式元素。如果不存在inline屬性。 jQuery的CSS樣式將呈現。元素內聯總是優先。如果元素中缺少style屬性,jquery css會替換該樣式。

$(function(){ 
 

 
if(!$("h1").attr("style")){ 
 
\t \t $("h1").css({ 
 
\t \t \t \t \t "margin":"7px", 
 
\t \t \t \t \t "border":"10px solid red !important", 
 
\t \t \t \t \t "padding":"10px" \t 
 
\t \t }); 
 
} 
 

 

 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<h1 style="margin:1px;border:1px solid red;padding:10px;" > 
 
Hello test 
 
</h1>

0

嘗試這樣做:

style="height: 351px !important;"