【发布时间】:2019-07-03 17:48:32
【问题描述】:
尝试使用ecmascript 6 变量连接。
在控制台中期望 exists 但出现错误。请帮忙:
let path = 'abc';
if($('.title[data-path=${path}]').length > 0){
console.log('exists');
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class='title' data-path = 'abc'>lorem</div>
<div class='title' data-path = 'def'>ipsum</div>
<div class='title' data-path = 'abc'>lorem</div>
【问题讨论】:
-
使用模板文字而不是
''
标签: javascript jquery