官术网_书友最值得收藏!

Time for action – adding task details

We will give each task the following new fields:

  • Start date: The date the task should start. The input type is date.
  • Due date: The date the task should be done by. The input type is date.
  • Status: Drop-down list <select> with options for None, Not Started, Started, and Completed.
  • Priority: Drop-down list <select> with options for None, Low, Normal, and High.
  • % Complete: The input type is number, with a valid range from 0 to 100.

Let's define these fields in the task template markup in taskAtHand.html. The details for each task will be displayed in a section under the task name. Our template now looks like the following code snippet:

<li class="task">
    <span class="task-name"></span>
    <input type="text" class="task-name hidden"/>
    <div class="tools">
        <button class="delete" title="Delete">X</button>
        <button class="move-up" title="Up">^</button>
        <button class="move-down" title="Down">v</button>
    </div>
    <div class="details">
 <label>Start date:</label>
 <input type="date"/><br/>
 <label>Due date:</label>
 <input type="date"/><br/>
 <label>Status:</label>
 <select>
 <option value="0">None</option>
 <option value="1">Not Started</option>
 <option value="2">Started</option>
 <option value="3">Completed</option>
 </select><br/>
 <label>Priority:</label>
 <select>
 <option value="0">None</option>
 <option value="1">Low</option>
 <option value="2">Normal</option>
 <option value="3">High</option>
 </select><br/>
 <label>%&nbsp;Complete:</label>
 <input type="number min="0" max="100" step="10" value="0"/>
 </div>
</li>

First we added a new <div class="details"> element to contain the new detail fields. This allows us to separate the details from the task name to style it differently. Then we added the labels and fields to it. Note that for % Complete we set the min and max attributes of the number field to limit the number between 0 and 100.

Next we need to style the details section. We will give it a gray background and rounded corners. We make all the labels of same width and align them to right so that all the input fields line up. We then set the <select> element of Status and Priority to a fixed width so they line up as well.

#task-list .task .details
{
    display: block;
    background-color: gray;
    color: white;
    border-radius: 4px;
    margin-top: 0.5em;
    padding: 0.25em;
    overflow: auto;
}
#task-list .task .details label
{
    width: 8em;
    text-align: right;
    display: inline-block;
    vertical-align: top;
    font-size: 0.8em;
}
#task-list .task .details select
{
    width: 8em;
}

What just happened?

We added a task details section to our tasks using some of the new HTML5 input types. The following screenshot shows what the task item looks like now with a details section:

主站蜘蛛池模板: 石棉县| 桐乡市| 额尔古纳市| 三门县| 永吉县| 天长市| 宿迁市| 朝阳市| 房产| 卓尼县| 酒泉市| 泸水县| 合川市| 酒泉市| 仙游县| 河津市| 顺义区| 方城县| 七台河市| 资阳市| 玛沁县| 吴江市| 红原县| 天水市| 来凤县| 彭阳县| 龙游县| 成武县| 扬州市| 西盟| 枣强县| 太原市| 专栏| 循化| 水城县| 罗田县| 高唐县| 衡山县| 大余县| 阿鲁科尔沁旗| 邵阳县|