jquery 如何使用现有的大写函数将setTagContents大写?

9ceoxa92  于 2023-02-08  发布在  jQuery
关注(0)|答案(1)|浏览(142)

外部文件中的大写脚本:

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>

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

p8h8hvxi

p8h8hvxi1#

$('.nav-swap-video li a').bind('click', function() {
        setTimeout(function() {
        $('#heading').text(capitalise($('#heading').text()));
    }, 0);
    });

相关问题