如何使用jquery识别以某种模式开头的html div id

dex*_*ter 0 html jquery

通常我们使用这样的东西来使用jquery来识别Id

 $("#PhotoId").html('some html');
Run Code Online (Sandbox Code Playgroud)

在这里我们得到具有id'PhotoId'的html(说div)如果id是部分动态的话,即假设有多张照片

每个id都以'PhotoId'EX开头.

 $("#PhotoId" + result.Id).html(some html');
Run Code Online (Sandbox Code Playgroud)

现在,我想识别以'PhotoId'开头的html(div)如何​​才能完成

And*_*air 5

http://api.jquery.com/attribute-starts-with-selector/

var elements = $('div[id^=PhotoId]');
Run Code Online (Sandbox Code Playgroud)

另一种方法是:
给元素一个类,例如.photoId那么你可以做那样的事情

var elements = $('div.photoId');
Run Code Online (Sandbox Code Playgroud)

这不会导致jQuery解析id-attributes div,而jQuery会对类进行简单匹配