Jquery:conatins显示警报所有跨度 [英] Jquery :conatins showing alert for all span

查看:123
本文介绍了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显示警报所有跨度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆