本文介绍了Jquery:conatins显示警报所有跨度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个跨栏< span style =font-weight:bold;>文字以< / span> $ b
$('#contentarea')。bind('click',function(e){ e.preventDefault(); if($(e.target).is('span')){ if($(e.target).find(:contains(font-weight:bold;))){{ alert('bold'); } } });我没有得到实际的结果,如果我点击任何span文本它会警告,请帮助我,我需要找出包含 font-weight:bold;
解决方案使用属性选择器...(如果您只需要选择包含风格属性为字体的范围..)
请尝试此
$('span [style ^ =font-]')这应该选择以 font -
$('span [style =font-weight:bold;]')
小提琴
I have a span <span style="font-weight: bold;">Text goes her</span> like this
$('#contentarea').bind('click',function(e){ e.preventDefault(); if($(e.target).is('span')){ if($(e.target).find(":contains(font-weight: bold;)")){{ alert('bold'); } } });i am not getting the actual result, if i click any span text it will alert,please help me, i need to find out the span contains the font-weight: bold;
解决方案you can use the attribute selector...(if you just need to select the span containing the style attribute as font..)
try this
$('span[style^="font-"]')this should select the span with style starting with font-
or
$('span[style="font-weight: bold;"]')fiddle
更多推荐
Jquery:conatins显示警报所有跨度
发布评论