如何使用 jQuery 获得跨度的这个值?
How can one get this value of a span with jQuery?
如果我们有这个 span
,我怎样才能得到 sip
的值,即 john.doe@xyz.de
<span class="ms-spimn-presenceWrapper ms-imnImg ms-spimn-imgSize-10x10">
<img name="imnmark" title="" showofflinepawn="1" class="ms-spimn-img ms-spimn-presence-disconnected-10x10x32" src="/_layouts/15/images/spimn.png?rev=23" alt="User Presence" sip="john.doe@xyz.de" id="imn_1,type=sip">;
</span>
现在我用
var projectLeaderName = $('#projectLeader span').html();
获取整个span的值,但是不知道如何用jQuery获取sip
的值。
我认为此屏幕截图不是必需的,但我会添加它以完成:
使用jQuery.attr
获取属性值:
var projectLeaderName = $('span img').attr('sip');
console.log(projectLeaderName);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<span class="ms-spimn-presenceWrapper ms-imnImg ms-spimn-imgSize-10x10">
<img name="imnmark" title="" showofflinepawn="1" class="ms-spimn-img ms-spimn-presence-disconnected-10x10x32" src="/_layouts/15/images/spimn.png?rev=23" alt="User Presence" sip="john.doe@xyz.de" id="imn_1,type=sip">;
</span>
如果我们有这个 span
,我怎样才能得到 sip
的值,即 john.doe@xyz.de
<span class="ms-spimn-presenceWrapper ms-imnImg ms-spimn-imgSize-10x10">
<img name="imnmark" title="" showofflinepawn="1" class="ms-spimn-img ms-spimn-presence-disconnected-10x10x32" src="/_layouts/15/images/spimn.png?rev=23" alt="User Presence" sip="john.doe@xyz.de" id="imn_1,type=sip">;
</span>
现在我用
var projectLeaderName = $('#projectLeader span').html();
获取整个span的值,但是不知道如何用jQuery获取sip
的值。
我认为此屏幕截图不是必需的,但我会添加它以完成:
使用jQuery.attr
获取属性值:
var projectLeaderName = $('span img').attr('sip');
console.log(projectLeaderName);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<span class="ms-spimn-presenceWrapper ms-imnImg ms-spimn-imgSize-10x10">
<img name="imnmark" title="" showofflinepawn="1" class="ms-spimn-img ms-spimn-presence-disconnected-10x10x32" src="/_layouts/15/images/spimn.png?rev=23" alt="User Presence" sip="john.doe@xyz.de" id="imn_1,type=sip">;
</span>