为什么点击按钮后无法显示?
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | <!DOCTYPE html> <html> <head> <meta charset= "UTF-8" > <title>下拉菜单组件</title> <link rel= "stylesheet" href= "css/base.css" /> <style type= "text/css" > body { background-color: gray; } .dropdown { position: relative; } .dropdown-toggle { position: relative; z-index: 2; } .dropdown-arrow { display: inline-block; /*background-repeat: no-repeat;*/ vertical-align: middle; } .dropdown-layer { display: none; position: absolute; z-index: 1; overflow: hidden; } .dropdown-left { left: 0; right: auto; } .dropdown-right { right: 0; left: auto; } /*.menu .dropdown*/ .menu .dropdown-toggle { display: block; height: 100%; padding: 0 16px 0 12px; border-left: 1px solid #f3f5f7; border-right: 1px solid #f3f5f7; } .menu .dropdown-arrow { /*width: 8px; height: 6px; background-image: url(../img/dropdown-arrow.png);*/ margin-left: 8px; } .menu .dropdown-layer { top: 100%; background-color: #fff; border: 1px solid #cdd0d4; } .menu-item { display: block; height: 30px; line-height: 30px; padding: 0 20px; color: #4d555d; white-space: nowrap; } .menu-item:hover { background-color: #f3f5f7; } .menu-active .dropdown-toggle { background-color: #fff; border-color: #cdd0d4; } .menu-active .dropdown-arrow { /*background-image: url(../img/dropdown-arrow-active.png);*/ } /*.menu-active .dropdown-layer { display: block; }*/ /* css 绘制箭头 .icon-triangle-down{ width:0px; height:0px; border:4px solid #535b62; border-right-color:transparent; _border-right-color:yellow; border-left-color: transparent; _border-left-color:yellow; border-bottom: none; } .menu-active .icon-triangle-down{ border-top: none; border-bottom:4px solid #f11c1c; }*/ @font-face { font-family: "iconfont" ; src: url( 'font/iconfont.eot?t=1477124206' ); /* IE9*/ src: url( 'font/iconfont.eot?t=1477124206#iefix' ) format( 'embedded-opentype' ), /* IE6-IE8 */ url( 'font/iconfont.woff?t=1477124206' ) format( 'woff' ), /* chrome, firefox */ url( 'font/iconfont.ttf?t=1477124206' ) format( 'truetype' ), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/ url( 'font/iconfont.svg?t=1477124206#iconfont' ) format( 'svg' ); /* iOS 4.1- */ } .icon { font-family: "iconfont" !important; font-size: 14px; font-style: normal; -webkit-font-smoothing: antialiased; -webkit-text-stroke-width: 0.2px; -moz-osx-font-smoothing: grayscale; } /*单独菜单旋转*/ /* .menu-active .dropdown-arrow { -o-transform: rotate(180deg); -ms-transform: rotate(180deg); -moz-transform: rotate(180deg); -webkit-transform: rotate(180deg); transform: rotate(180deg); }*/ /*多菜单旋转*/ [class*= "-active" ] .dropdown-arrow { -o-transform: rotate(180deg); -ms-transform: rotate(180deg); -moz-transform: rotate(180deg); -webkit-transform: rotate(180deg); transform: rotate(180deg); } .transition { -o-transition: all 0.5s; -ms-transition: all 0.5s; -moz-transition: all 0.5s; -webkit-transition: all 0.5s; transition: all 0.5s; } .fadeOut { visibility: hidden !important; opacity: 0 !important; } .slideUpDownCollapse { height: 0 !important; padding-top: 0 !important; padding-bottom: 0 !important; } .slideLeftRightCollapse { width: 0 !important; padding-left: 0 !important; padding-right: 0 !important; } .dropdown-loading{ width:32px; height: 32px; background: url(../img/loading.gif) no-repeat; margin: 20px; } </style> </head> <body> <!-- 通用html代码 <div class= "menu dropdown" > <div class= "dropdown-toggle" >我的慕淘<i class= "dropdown-arrow" ></i></a> <div class= "dropdown-layer dropdown-left" > </div> </div> --> <!-- <div class= "menu dropdown fl" data-active= "menu" > <a class= "dropdown-toggle" >我的慕淘<i class= "dropdown-arrow" ></i></a> <ul class= "dropdown-layer dropdown-left" > <li><a href= "###" target= "_blank" class= "menu-item" >已买到的宝贝</a></li> <li><a href= "###" target= "_blank" class= "menu-item" >我的足迹</a></li> </ul> </div> --> <div class= "menu dropdown fl" data-active= "menu" data-load= "dropdown.json" > <a href= "javascript:;" class= "dropdown-toggle" >我的慕淘<i class= "dropdown-arrow icon transition" >& #xe609;</i></a> <ul class= "dropdown-layer dropdown-left" > <li class= "dropdown-loading" ></li> <!-- 解决按需加载。使用json文件--> <!-- <li><a href= "###" target= "_blank" class= "menu-item" >已买到的宝贝</a></li> <li><a href= "###" target= "_blank" class= "menu-item" >我的足迹</a></li> --> </ul> </div> <!-- <div class= "menu dropdown fl" data-active= "menu" > --> <!-- <a href= "javascript:;" class= "dropdown-toggle" >我的慕淘2<i class= "dropdown-arrow icon transition" >& #xe609;</i></a> --> <!-- <ul class= "dropdown-layer dropdown-left" > --> <!-- <li><a href= "###" target= "_blank" class= "menu-item" >已买到的宝贝</a></li> <li><a href= "###" target= "_blank" class= "menu-item" >我的足迹</a></li> --> <!-- </ul> --> <!-- </div> --> <!-- <div class= "menu dropdown fl" data-active= "menu" > <a href= "javascript:;" class= "dropdown-toggle" >我的慕淘2<i class= "dropdown-arrow icon transition" >& #xe609;</i></a> <ul class= "dropdown-layer dropdown-left" > <li><a href= "###" target= "_blank" class= "menu-item" >已买到的宝贝2</a></li> <li><a href= "###" target= "_blank" class= "menu-item" >我的足迹2</a></li> </ul> </div> <div class= "menu dropdown fl" data-active= "menu" > <a href= "javascript:;" class= "dropdown-toggle" >我的慕淘3<i class= "dropdown-arrow icon transition" >& #xe609;</i></a> <ul class= "dropdown-layer dropdown-left" > <li><a href= "###" target= "_blank" class= "menu-item" >已买到的宝贝3</a></li> <li><a href= "###" target= "_blank" class= "menu-item" >我的足迹3</a></li> </ul> </div> --> <button id= 'btn-show' >点我显示</button> <button id= 'btn-hide' >点我隐藏</button> <script src= "js/jquery.js" ></script> <script src= "js/transition.js" ></script> <script src= "js/showHide.js" ></script> <script src= "js/dropdown.js" ></script> <script type= "text/javascript" > // -----简单写法----- // $('.dropdown').hover(function() { // var $this=$(this); // 缓存this,以避免重复加载 // $this.addClass($this.data('active')+'-active'); // }, function() { // var $this=$(this); // $this.removeClass($this.data('active')+'-active'); // }); //------封装代码方式-------- // function dropdown(elem) { // var $elem = $(elem), // activeClass = $elem.data('active') + '-active'; // $elem.hover(function() { // $elem.addClass(activeClass); // }, function() { // $elem.removeClass(activeClass); // }); // } //单个下拉菜单 dropdown($('.dropdown')[0]) //多个下拉菜单 // $('.dropdown').each(function(){ // dropdown($(this)); // }); // ------插件方式------- // function dropdown(elem) { // var $elem = $(elem), // activeClass = $elem.data('active') + '-active'; // $elem.hover(function() { // $elem.addClass(activeClass); // }, function() { // $elem.removeClass(activeClass); // }); // } // $.fn.extend({ // dropdown:function(){ // return this.each(function(){ // dropdown(this); // }); // } // }); // $('.dropdown').dropdown(); // 插件为了更好的调用 // $('.dropdown').on('dropdown-show dropdown-shown dropdown-hide dropdown-hidden',function (e) { // console.log(e.type); // }) // $('.dropdown').on('dropdown-show', function(e) { // var $this=$(this), // dataLoad=$(this).data('load'); // if(!dataLoad) return; // // $layer.html('<li class="dropdown-loading"></li>'); // if(!$this.data('loaded')){ // var $layer = $(this).find('.dropdown-layer'), // html = ''; // $.getJSON(dataLoad, function(data) { // console.log(1); // setTimeout(function() { // for (var i = 0; i < data.length; i++) { // html += '<li><a href="' + data[i].url + '" target="_blank" class="menu-item">' + data[i].name + '</a></li>' // } // $layer.html(html); // $this.data('loaded',true); // }, 1000); // }); // } // }); $( '.dropdown' ).on( 'dropdown-show' , function (e) { var $layer=$( this ).find( '.dropdown-layer' ), html= '' ; $.getJSON( 'dropdown.json' , function (data){ // console.log(data); for ( var i=0;i<data.length;i++){ html+= '<li><a href="' +data[i].url+ '" target="_blank" class="menu-item">' +data[i].name+ '</a></li>' } $layer.html(html); }); }); $( '.dropdown' ).dropdown({ event: 'hover' , delay: 1000, css3: true , js: true , animation: 'fade' // active:'menu' }); $( '#btn-show' ).on( 'click' , function () { $( '.dropdown' ).dropdown( 'show' ); }); $( '#btn-hide' ).on( 'click' , function () { $( '.dropdown' ).dropdown( 'hide' ); }); </script> </body> </html> [ { "url" : "###" , "name" : "已买到的宝贝" }, { "url" : "###" , "name" : "我的足迹" }, { "url" : "###" , "name" : "我的优惠券" } ] |
1
收起
正在回答
2回答
同学你好, 老师在源码中将你的这部分代码粘贴过去, 测试你这段代码, 是可以正常显示的内容的哦,示例:
同学说的不能显示具体是指什么不能显示呢, 可以详细的描述一下做了什么操作哦,或者打开控制台查看是否有报错信息, 如果有问题, 可以截图过来, 再次提问, 我们会继续为你解答的
如果帮助到了你, 欢迎采纳!
祝学习愉快~~~~
qq_鸭绿桥第一帅哥_0
2019-06-18 13:14:39
感谢老师,目前已经可以正常显示了。但是控制台为什么会报错呢?
组件化思想开发电商网页 18版
- 参与学习 人
- 提交作业 467 份
- 解答问题 4826 个
本路径带你通过系统学习HTML5、JavaScript、jQuery的进阶知识,不仅如此,还会学习如何利用组件化的思想来开发网页,知识点+案例,使得所学可以更好的得到实践。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧