0

I am working on a new masterpage withing sharepoint 2010. One of the placeholders produces the sitename - the page name in a string. When the page is ready the sources shows this for exampe.

<h1 class="ribbonmc">
    Devness Squared - Mark Jensen
</h1>

Devenss Squared is the site name and Mark Jensen is the page name. I am trying to remove the sitename from being displayed and show the page name only using jQuery. This is what I have so far.

$(document).ready(function() {
        $('#ribbonmc').text(function(i, oldText) {
            return oldText === 'Devness Squared - ' ? '' : oldText;
        });
    });
4

2 回答 2

0

正则表达式解决方案:

$(".ribbonmc").text(function(i, oldText) {
    return oldText.replace(/^Devness Squared - /, "");
});

非正则表达式解决方案:

$(".ribbonmc").text(function(i, oldText) {
    var r = "Devness Squared - ";
    return oldText.indexOf(r) === 0 ? oldText.substring(r.length) : oldText;
});
于 2013-01-22T21:35:59.123 回答
0
$(document).ready(function() {
    var sitename = 'Devness Squared - ';
    $(".ribbonmc").text(function(i, oldText) {
        return oldText.indexOf(sitename) === 0    // if it starts with `sitename`
             ? oldText.substring(sitename.length) // t: return everything after it
             : oldText;                           // f: return existing
    });
});
于 2013-01-22T21:38:58.243 回答