English 中文(简体)
如何根据案文增加额外归属
原标题:How to add additional attribute according to the text

这是我的超文本法典。

<div id="ccc_new_val_hdn">
    <span>9</span>
    <span>,</span>
    <span> </span>
    <span>6</span>
    <span>2</span>
    <span>1</span>
</div>

I need to convert comma and space like this

<span class= comma >,</span>

and space to

<span class= space > </span>

我尝试了:找到(),但不能拿到法典。

最佳回答

修补课。

$( #ccc_new_val_hdn span ).each(function() {
    if($(this).html() ==  , ){
        $(this).addClass( comma );
    }
    if($(this).html() ==    ){
        $(this).addClass( space );
    }
});

Demo:

问题回答

你可以选择四舍五入和三米内的所有界限,然后检查这些数值,然后才能确定你希望适用的等级。

$(document).ready(function(){
    $( #ccc_new_val_hdn span ).each(function(){
        var text = $.trim($(this).text());
        if(text ===  , )
            $(this).addClass( comma )
        else if(text === "")
            $(this).addClass( space );
    });
});

替代案文

$( #ccc_new_val_hdn span ).each(function() {
    if($(this).text() ==  , ){
        $(this).addClass( comma );
    }
    if($(this).text() ==    ){
        $(this).addClass( space );
    }
});




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!