Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果当前 id 为空,我想添加一个 id。我认为这可以完成这项工作:
$(".file-row[id='']").attr('id', 'imageId'+imageId);
但事实并非如此。为什么不?
如果 id 为空或全部缺失,则设置 id。
$('div').filter('[id=""],:not([id])').prop('id', 'newId');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="">One</div> <div>Two</div> <div id="three">Three</div>