JavaScript练习

By admin, 14 十一月, 2016

在上一节CSS练习的基础上加一个按钮,点击按钮之后表头的变成黑底灰字(#ccc),表身颜色变成灰底(#ccc)黑字。

学号 姓名 年级 班别
1101 陈一 一年级 1
1102 袁二 一年级 1
1203 张三 一年级 2
2104 李四 二年级 1
2205 王五 二年级 2

提示,可按以下步骤实现:

  1. 先用getElementsByTagName获取表头元素th和表身元素td(参考:http://www.w3school.com.cn/jsref/met_doc_getelementsbytagname.asp
  2. getElementByTagName返回的结果是一个数组,包含多个th或td元素,我们需要用一个循环来遍历里面的内容(参考:http://www.w3school.com.cn/js/js_loop_for.asp
  3. 获得具体元素之后,我们通过修改其style属性实现改变样式(http://www.w3school.com.cn/js/js_htmldom_css.asp )。
  4. 改变背景样式可以参考http://www.w3school.com.cn/jsref/prop_style_backgroundcolor.asp
  5. 做一个按钮,参考:http://www.w3school.com.cn/tags/tag_button.asp 。添加一个onclick时间相应用户的点击,参考:http://www.w3school.com.cn/tags/event_onclick.asp
  6. 点击按钮后调用一个函数,函数体执行上面1-4的操作。参考:http://www.w3school.com.cn/js/js_functions.asp

 

评论

Restricted HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img src>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。
验证码
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
请输入"Drupal10"