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

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:

主站蜘蛛池模板: 正蓝旗| 报价| 南溪县| 鄂伦春自治旗| 左贡县| 长沙县| 大丰市| 民权县| 永和县| 博爱县| 东城区| 广宗县| 丰台区| 镇康县| 博白县| 红安县| 布尔津县| 方正县| 长宁区| 义马市| 五河县| 资溪县| 宝山区| 杂多县| 内江市| 万载县| 花莲县| 莱西市| 永靖县| 缙云县| 遵义市| 绵竹市| 普定县| 攀枝花市| 长寿区| 芒康县| 江安县| 永定县| 缙云县| 禄丰县| 台东市|