jQuery18(小广告效果,动态创建表格)
2016-02-07 00:09
627 查看
小广告效果
知识点:bottom是末端的意思.另外,因为直接在这里写html,所以,小心一些在html和js中不同的写法.完整实例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="jquery-1.8.3.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { $('#btn').click(function () { //parent 父元素 //注意的是这里是直接写html,所以background-color这种写法 //这里注意bottom 低端 末端 不是down 汗 //使用parent 删除父元素 //float:rigth将X定至右上角 var dvOvj = $('<div style="width:300px;height:200px;background-color:green;position:absolute;right:0;bottom:0"></div>').appendTo($('body')); $('<span style="float:right; cursor:pointer;">X</span>').click(function () { $(this).parent().remove(); }).appendTo(dvOvj); }); }); </script> </head> <body> <input type="button" name="name" value="显示广告" id='btn' /> </body> </html>
4000
动态创建表格
知识点:键值对的key值不能相同完整实例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="jquery-1.8.3.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { //在这边需要注意的是键值对 key的值不能相同,相同时,不会报错,但是只会显示一个 var dic = { '百度': 'http://www.baidu.com', '百度1': 'http://www.baidu.com', '百度2': 'http://www.baidu.com', '百度3': 'http://www.baidu.com', '百度4': 'http://www.baidu.com' }; $('#btn').click(function () { var tb = $('<table border=1></table>').appendTo($('body')); for (var key in dic) { $('<tr><td>' + key + '</td><td><a href=' + dic[key] + '>' + key + '</a></td></tr>').appendTo(tb); } }); }); </script> </head> <body> <input type="button" name="name" value="创建表格" id='btn' /> </body> </html>
相关文章推荐
- jQuery17(html,attr,removeAttr,动态创建元素)
- jquery闭包
- 26个Jquery使用小技巧
- jQuery16(内容过滤器,子元素过滤器)
- JQuery 基本知识
- jquery 点击其他地方
- jQuery15(元素each方法,表单选择器)
- jQuery14(表单过滤器及注意事项)
- jQuery-品牌列表案例
- [转]浅谈jQuery EasyUI的属性设置
- jQuery实现简单拖拽
- jQuery源码解析1(Utilities)
- 用户界面框架jQuery EasyUI示例大全之DataGrid(2/4)
- jQuery-认识JQuery,jQuery选择器
- jQuery13(相对元素的练习)
- jQuery12(prev练习,相对元素)
- jQuery scrollFire插件
- jQuery11(过滤器的3个练习)
- jQuery10(过滤器)
- jQuery9(操作类选择器,开关灯)