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

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:

主站蜘蛛池模板: 大冶市| 渑池县| 甘谷县| 绥化市| 淮南市| 申扎县| 汕尾市| 德清县| 教育| 北碚区| 涟水县| 同德县| 吉安市| 阳曲县| 崇信县| 安庆市| 贺州市| 东宁县| 禄劝| 乳山市| 祁东县| 镶黄旗| 香格里拉县| 广元市| 白城市| 海晏县| 南京市| 盐津县| 南京市| 高安市| 青阳县| 渑池县| 长岛县| 江陵县| 郁南县| 苏尼特左旗| 永安市| 高州市| 合山市| 铜陵市| 永济市|