Question

J'ai une question simulée à un problème résolu, mais dans mon environnement, la solution ne fonctionne pas.

Dans un SharePoint, il y a une table avec des colonnes et je veux changer la couleur d'arrière-plan en vert d'un seul TD lorsque le contenu est comme "vert".

J'ai essayé ça

<table>
    <tr>
        <table>
            <tr>
                <th width="200px">Title</th>
                <th width="100px">State</th>
            </tr>
            <tr>
                <td>Hello</td>
                <td>Green</td>
            </tr>
            <tr>
                <td>World</td>
                <td>Red</td>
            </tr>
        </table>
    </tr>
</table>
<script>
    $("td:contains('Green')").css('background-color', '#00FF00');
</script>

Mon exemple sur jsfiddle

Mais cela ne fonctionne pas à la structure de table à table SharePoint. Pourquoi? Quel est le problème? L'ensemble du tableau est du peinture dans la couleur de la dernière valeur.

Était-ce utile?

La solution

Incluez d'abord le fichier jQuery

puis après

Écrivez votre code comme

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script>

<script>
$(document).ready(function(){
$("td:contains('Green')").css('background-color', '#00FF00');
});
</script>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top