0

外部文件中的大写脚本:

function capitalise(str) {
        if (!str) return;
        var counter = 0;
        var stopWords = ['is','a','an','and','at','but','by','far','from','if','into','in','of','off','on','or','so','the','to','up','with'];
        str = str.replace(/\b\S*[a-z]+\S*\b/ig, function(match) {
            counter++;
            return $.inArray(match, stopWords) == -1 || counter === 1 ? match.substr(0, 1).toUpperCase()+match.substr(1) : match;
        });
        return str;
    }

内联 JavaScript:

<ul class="nav-swap-video">
    <li><a id="nav-content1" class="" href="#st-mv1" onclick="changeVideo('../video/video_arriving.mpg');setTagContents('heading', 'Arriving');switchButton('1')" title="Arriving">Arriving
      <div class="video-nav-bottom"></div>
      </a>
    </li><li><a id="nav-content2" href="#st-mv2" onclick="changeVideo('../video/video_in_bag.mpg');setTagContents('heading', 'In the bag');switchButton('2')" title="In the bag" class="">In the bag
      <div class="video-nav-bottom"></div>
      </a>
      </li><li><a id="nav-content3" href="#st-mv3" onclick="changeVideo('../video/video_getting_ready.mpg');setTagContents('heading', 'Getting ready');switchButton('3')" title="Getting ready" class="nav-on-xx">Getting ready
      <div class="video-nav-bottom"></div>
      </a>
    </li><li><a id="nav-content4" href="#st-mv4" onclick="changeVideo('../video/video_after_swim.mpg');setTagContents('heading', 'After a swim');switchButton('4')" title="After a swim" class="">After a swim
      <div class="video-nav-bottom"></div>
      </a>
    </li></ul>

我需要在设置标签内容后将其大写。谢谢

4

1 回答 1

0
$('.nav-swap-video li a').bind('click', function() {
        setTimeout(function() {
        $('#heading').text(capitalise($('#heading').text()));
    }, 0);
    });
于 2012-08-15T10:23:58.043 回答