JQuery添加新元素
2015-11-24 19:50
861 查看
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | <metahttp-equiv= "Content-Type" content= "text/html;charset=utf-8" > <title>第一个JQuery文档</title> <scriptsrc= "jquery.js" ></script> <scripttype= "text/javascript" > //使用JQuery操纵网页元素,实现新元素添加并绑定事件。 $(document).ready( function (e){ $( "#msg" ).css( "font-size" , "9px" ); //更改DIV元素的字体 $( "#msg" ).click( function (e){ alert($( this ).html()); } ); //为DIV元素添加CLICK响应 $( "<b>Hello World!</b>" ).appendTo( "body" ); //向页面BODY添加一个新的B元素 $( "<div>" ,{ style: "width:200px;height:200px;background-color:silver;" }).hover( function (){ alert( '鼠标移入!' );}, function (){alert( '鼠标移出!' ); } ) .appendTo( "body" ); //向页面BODY添加一个新的DIV元素,并添加JQuery的hover事件响应。 /* *hover()是jQuery为了方便用户固定调用mouseenter和mouseleave事件而重新定义的内部事件,它并非一个真正的事件,不能使用bind()绑定。 *所以使用以下代码是无法实现Hover事件绑定效果的。 */ $( "<div>" ,{ style: "width:200px;height:200px;background-color:purple;" }).bind({hover:( function (){ alert( 'mouseover' ); }, function (){alert( 'mouseout' ); } ) }).appendTo( "body" ); /* *可以直接绑定mouseenter/mouseleave或mouseover/mouseout事件达到与Hover事件相同效果。 */ $( "<div>" ,{style: "width:200px;height:200px;background-color:maroon;" }).bind({ mouseover:( function (){ alert( 'mouseover' ); }) }).bind({ mouseout:( function (){ alert( 'mouseout' ); }) }).appendTo( "body" ); $( "<div>" ,{ style: "font-size:9px;background-color:navy;width:200px;height:200px;" , text: "单击这里改变颜色" , click: function (){ $( this ).css( "background-color" , "green" );}, mouseenter: function (){ $( this ).css( "background-color" , "blue" );}, mouseleave: function (){ $( this ).css( "background-color" , "yellow" );} }).appendTo( "body" ); $( "<div>" ,{style: "width:200px;height:200px;background-color:olive;" }).bind({ click:( function (){ alert( 'mouseclick' ); }) }).appendTo( "body" ); //向页面BODY添加一个新的DIV元素,并添加CLICK响应。 } ); </script> <divid= "msg" style= "width:200px;height:200px;background-color:red" ><span>第一个JQuery文档</span></div> |
相关文章推荐
- jquery的插件写法
- jquery ajax 请求和json 解析
- jquery 首页轮播插件 icarouselbox.js
- jQuery效率提升建议
- anjular绑定jquery
- jQuery-1.9.1源码分析系列(十一) DOM操作
- 关于jquery stopPropagation()阻止冒泡事件
- jquery给table动态添加tr
- jquery中ajax的dataType属性包括哪几项
- jquery select取值,赋值操作
- JS字符串替换(jQuery)
- [JavaScript/JQuery] jQuery图片缩小效果
- jquery视频展示 图片轮播
- jquery根据name属性查找
- 对jQuery插件的一点点认识
- jQuery实现宽屏图片轮播实例教程
- js和jquery获取各种宽度和盖度
- jquery 中substring,substr,split的用法
- jquery设置个滚动条位置,使页面回到顶端
- jquery利用拖拽方式在图片上添加热链接