我加入動態使用jQuery像這樣一個div:條件和動態添加的div類與jQuery
$('#content').append('<div class="tiles color m-b-10">some text</div>');
我想類值「顏色」由「綠色」來代替,如果x> 0, 「紅色」,否則
我試過以下(在變化,沒有引號,單引號和雙引號等),但似乎沒有任何工作。
$('#content').append('<div class="tiles'+ x > 0 ? "green" : "red"+ ' m-b-10">some text</div>');`enter code here`
我的問題是a)是否可行? b)如果是,如何?
什麼是HTML?我認爲這與你解釋 – Sherlock