简体   繁体   中英

Mixing Javascript inside HTML

There isa D3.js drawing function that is accepting element and d as data for its params and inside that function there are some HTML lines like this that draw some stuff:

'<p><strong>' + d.name_detail[0].detail_value + '</strong> ' + d.name_detail[1].detail_value +
'<strong class="pharmacy-icon">' + d.generic_tooltip.length +
'<img src="/assets/pill.png">' +
'</img></strong></p>' +

Notice the line '<img src="/assets/pill.png">' + I need to put some logic in there to say for example if d.showpill === true then show the pill icon otherwise don't show it. But currently it is always showing.

'<p><strong>' + d.name_detail[0].detail_value + '</strong> ' + d.name_detail[1].detail_value +
'<strong class="pharmacy-icon">' + d.generic_tooltip.length +
(d.showpill === true ?'<img src="/assets/pill.png"></img></strong></p>' : '</strong></p>')

如果内联:

((d.showpill == true) ? '<img src="/assets/pill.png"> : '')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM