2012-08-14 62 views
0

资本化脚本的外部文件:如何使用现有的大写函数来设置setTagContents?

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> 

我需要它已经被设置后,大写设置标签内容。谢谢

回答

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