4

私は最近、jQuery で Javascript のみを使用して、求人応募の 30 分間のテストを行いました。スタイルを良くする必要はありませんでした。Javascript と jQuery を使用して非常に基本的な「30 分」のページを作成しましたが、これは「大丈夫」だと思いました。結局、私は仕事を得ることができませんでした.. 常に学んでいて、仕事は私が住んでいる場所からかなり離れていました.

とにかく、提供された元の HTML ページは次のとおりでした。その後、基本的な HTML をタブ ベースのコンテンツ ページに変換するための私のささやかな試みです - 再び 30 分以内に。

<html>
<head>

<!-- stylesheet, javascript, etc. here -->

</head>
<body>

<h1>My Page</h1>

<h2 class="subheading">The first section</h2>
<div class="content">
    <p>Lorem ipsum...</p>
</div>

<h2 class="subheading">The second section</h2>
<div class="content">
    <img src="/some_image" alt="Image" title="Image"></img>
    <p>Some other text</p>
</div>

<h2 class="subheading">The third section</h2>
<div class="content">
    And some more text here
</div>


<div class="footer">
    This is at the foot of the page
</div>

</body>
</html>

わかりましたので、私の謙虚な試みは次のとおりです。

<html>
<head>
    <title>Test JS page</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

    <style type="text/css">
        #tabs
        {
            width:457px;
            height:60px;
        }
        #tab1, #tab2, #tab3
        {
            width:150px;
            border:1px solid #ccc;
        }
        #tab1
        {
            float:left;
        }
        #tab3, #tab2
        {
            float:right;
        }
        #tab2_content, #tab3_content
        {
            display:none;
        }
        .clear
        {
            clear:both;
        }
        #content
        {
            height:300px;
        }

    </style>

    <script type="text/javascript">
    $(document).ready(function () {

        $('#tab1_link').click(function (e) {
            e.preventDefault();
            clearContent();
            $('#tab1_content').show();
        });

        $('#tab2_link').click(function (e) {
            e.preventDefault();
            clearContent();
            $('#tab2_content').show();
        });

        $('#tab3_link').click(function (e) {
            e.preventDefault();
            clearContent();
            $('#tab3_content').show();
        });

    });

    function clearContent() {
        $("div[id*='_content']").each(function() {
            $(this).hide();
        });
    }

    </script>

</head>

<body>

<h1>My Page</h1>

<div id="tabs">
    <div id="tab1"><a id="tab1_link" class="subheading">The first section</a></div>
    <div id="tab2"><a id="tab2_link" class="subheading">The second section</a></div>
    <div id="tab3"><a id="tab3_link" class="subheading">The third section</a></div>
</div>

<div class="clear">
</div>

<div id="content">

    <div id="tab1_content" class="content">
        <p>Lorem ipsum...</p>
    </div>

    <div id="tab2_content" class="content">
        <img src="/some_image" alt="Image" title="Image"></img>
        <p>Some other text</p>
    </div>

    <div id="tab3_content" class="content">
    And some more text here
    </div>    

</div>

<div class="footer">

This is at the foot of the page

</div>

</body>
</html>

ご覧のとおり、確かではありません..スタイルシートはスクリプトと同様にインラインでしたが、これは、タスクを実行するのに十分なJavascript/jQueryを知っているかどうかを示すためのテストでした..そうではないと思いました.素晴らしいですが、それほど悪くもありません..

望ましい結果を達成するための他の方法についてのフィードバックに感謝します..繰り返しますが、きれいである必要はなく、機能的である必要はありません..もちろん、すべて30分以内に..

ありがとう!

4

3 に答える 3

5
<div id="tabs">
    <ul>
        <li><a href="#tabs-1">The First Section</a></li>
        <li><a href="#tabs-2">The Second Section</a></li>
        <li><a href="#tabs-3">The Third Section</a></li>
    </ul>
   <div id="tabs-1" class="content">
        <p>Lorem ipsum...</p>
   </div>

   <div id="tabs-2" class="content">
       <img src="/some_image" alt="Image" title="Image"></img>
   </div>

   <div id="tabs-3" class="content">
      <p>Some other text</p>
   </div>
</div>

<script>
   $(function() {
    $("#tabs").tabs();
   });
</script>

http://jqueryui.com/demos/tabs/

于 2012-06-09T14:44:18.287 に答える
1

これには jQuery UI は必要ありません。

デモhttp://jsbin.com/atogil/2/edit

HTML

<div class="tabs">
    <nav class="tab-btns">
        <a href="#tab1">tab btn 1</a>
        <a href="#tab2">tab btn 2</a>
        <a href="#tab3">tab btn 3</a>
        <a href="#tab4">tab btn 4</a>
    </nav>
    <div class="tab-contents">
        <div id="tab1">tab content 1</div>
        <div id="tab2">tab content 2</div>
        <div id="tab3">tab content 3</div>
        <div id="tab4">tab content 4</div>
    </div>
</div>

JS

$.fn.myTabs = function(settings){
  return this.each(function() {

/*
save cached version of the first elements inside the containers. 
by calling the first elements of each container you are not limitng 
the plugin user to any specific class or elememt.
*/
    var btns = $(settings.nav, this).children(),
        tabs = $(settings.tabs, this).children();


/* 
we relying on the order of the elements as the conection between 
the buttons and the tabs notice that .each() get the index of the btn..
we are useinf it to find the current tab.
*/

        btns.each(function(index){
            var btn = $(this),
                tab = tabs.eq(index);


            btn.click(function (e){
                /* prevent unnesscry work by checking 
                   if the button clicked is already active  */
                if(btn.is('.active')) return false;

                /* notice that first filter to find the last 'active' 
                   button before we remove the 'active' class  otherwise it 
                   remove the class for every button. 
                   unnesscry work prevented again */
                btns.filter('.active').removeClass('active');

                /* hide previus tab.. */
                tabs.filter(':visible').hide();

                btn.addClass('active');
                tab.show();


                return false;
            });
        });

        // emulate click on the first tab button;
        btns.first().click();
  });
};

次のようにスクリプトを呼び出します。

$(function() {

  $('.tabs').myTabs({
    // container of navigation inside '.tabs'
    nav : '.tab-btns',
    // container of contents inside '.tabs'
    tabs : '.tab-contents'
  });

});
于 2013-01-11T20:01:03.943 に答える
1

会社について何も知らずに、彼らが探しているものを言うのは難しいため、テストを受けていました。

一般的に、雇用主は完璧なコードを求めているのではなく、問題にどのようにアプローチするかを求めています。たとえば、あなたが彼らの指示にやみくもに従うか、外部スタイル/スクリプト参照を追加するか、クリーンで標準に準拠した簡潔なコードを追加するという慣習と優れた慣行に固執するかを確認しようとしていると言えます。

私は完全な初心者ですので、私が言うことをあまり真剣に受け止めないでください。しかし、再利用可能な簡潔なコードを作成しようと試みました。これらのことを忘れてよいという意味ではありません)。

これを非常に大まかに、頭のてっぺんから外しただけですが、次のようなことをしています:

$('#tab-menu').click(function(e) {
   e.preventDefault();
   clearContent();
   $(this).show();
});

モバイル デバイスに関係する会社の場合は、おそらくイベントをバインドして、同じ機能を取得したいと思うでしょう。

私がいつも行ってきたことは、たとえそれがメモ帳にあったとしても、前提条件のドキュメントを提供することです。ガンホーに行くのではなく、立ち止まって何をしなければならないかを考えていることを示しているため、常に前向きに見られています。

総じてよく頑張ったと思います!あなたは素晴らしい態度を持っており、このような経験から学び、改善し、より良くなります! 今日の後輩が明日の達人に!私たちが十分に頑張れば

于 2012-06-09T14:39:25.777 に答える