2010-12-01 3 views

답변

2

"tabview.get ('selection')"을 인수로 사용하면 "indexOf"가 실제로 작동합니다.

예 :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
     <title>Untitled Document</title> 
    <script type="text/javascript" charset="utf-8" 
     src="http://yui.yahooapis.com/3.2.0/build/yui/yui-min.js"> 
    </script> 
    </head> 
    <body> 
     <body class="yui3-skin-sam"> 
     <p id="msg"></p> 
    <input type='button' value='Button' id='button'/> 
    <div id="demo"> 
     <ul> 
      <li><a href="#foo">foo</a></li> 
      <li><a href="#bar">bar</a></li> 
      <li><a href="#baz">baz</a></li> 
     </ul> 
     <div> 
      <div id="foo">foo content</div> 
      <div id="bar">bar content</div> 
      <div id="baz">baz content</div> 
     </div> 
    </div> 
    <script> 
var YUI; 
YUI().use('event', 'node', 'tabview', function (Y) { 
    Y.one('#msg').set('innerHTML', 'message area'); 

    var tabview = new Y.TabView({srcNode: '#demo'}); 
    tabview.render(); 

    var displayIndex = function (tabview) { 
    var sel = tabview.get('selection'); 
    var idx = tabview.indexOf(sel); 
    Y.one('#msg').set('innerHTML', 'Selected Tab Index = ' + idx); 
    } 
    displayIndex(tabview); 

    Y.after('click', function(e) { 
    displayIndex(this); 
    },'body',tabview); 

}); 
    </script> 
    </body> 
</html> 
+0

내가 필요 정확히, 감사합니다. – Evert

+0

선택시주의하십시오. selection을 사용하면 여러 선택 항목을 사용할 수있는 경우 위젯 인스턴스 또는 ArrayList를 반환 할 수 있습니다. 더 나은 선택은 tabview.get ('activeDescendant') 일 수 있습니다. 위젯 인스턴스 만 반환합니다. tabview/tab은 widget-parent/widget-child 확장을 사용합니다. http://developer.yahoo.com/yui/3/api/WidgetParent.html 및 http://developer.yahoo.com/yui/3/api/WidgetChild.html – bigwebguy

+0

@bigwebguy에서 문서를 확인하십시오. 머리를 위로 thx. – mjhm