标签 3.1版本之后请到这个地方查看文档

4.19.1 标签输入效果

Hui前端框架 CSS3 HTML5
前端框架 前端开发 H-ui

HTML代码

  1. <div class="Hui-tags">
  2. <div class="Hui-tags-editor cl"><i class="Hui-tags-icon Hui-iconfont">&#xe64b;</i> <span class="Hui-tags-token">Hui前端框架</span> <span class="Hui-tags-token">CSS3</span> <span class="Hui-tags-token">HTML5</span>
  3. <div class="Hui-tags-iptwrap">
  4. <input type="text" class="Hui-tags-input" maxlength="20" value="">
  5. <label class="Hui-tags-label">添加相关标签,用空格或回车分隔</label>
  6. </div>
  7. </div>
  8. <div class="Hui-tags-list">
  9. <div class="Hui-notag" style="display:none">暂无常用标签</div>
  10. <div class="Hui-tags-has"><span>前端框架</span> <span>前端开发</span> <span>H-ui</span></div>
  11. </div>
  12. <input type="hidden" class="Hui-tags-val" name="" value="">
  13. </div>

CSS代码

  1. .Hui-tags{border:solid 1px #dedede; padding:0 10px}
  2. .Hui-tags-editor{position:relative; padding:10px 0 10px 24px}
  3. .Hui-tags-editor .Hui-tags-icon{position:absolute; left:0; top:11px; font-size:14px; color:#666}
  4. .Hui-tags-token{color:#aaa; float:left; font-size:12px; height:20px; line-height:20px; margin-right:8px; padding:0 1px; white-space:nowrap; cursor:pointer}
  5. .Hui-tags-token:before{content:"#"}
  6. .Hui-tags-token:hover{text-decoration:line-through}
  7. .Hui-tags-iptwrap{position:relative; float:left}
  8. .Hui-tags-input{position:relative;height:20px;min-width:60px; border:0 none; vertical-align:top;line-height:20px; color:#333;z-index:2;background: url(../images/empty.png) repeat scroll 0 0; display:inline-block; width:100%}
  9. .Hui-tags-label{position:absolute; top:0; left:2px; width:240px; height:20px; line-height:20px; font-size:14px; overflow:hidden; z-index:1; color:#ccc}
  10. .Hui-tags-list{padding:0 0 10px 0; display:none}
  11. .Hui-notag{font-size:12px}
  12. .Hui-tags-has span{cursor:pointer; font-size:12px; white-space:nowrap; margin-right:10px}

JS代码

  1. var time1;
  2. $(".Hui-tags-lable").show();
  3. $(".Hui-tags-input").val("");
  4. $(document).on("blur",".Hui-tags-input",function(){
  5. time1 = setTimeout(function(){
  6. $(this).parents(".Hui-tags").find(".Hui-tags-list").slideUp();
  7. }, 400);
  8. });
  9. $(document).on("focus",".Hui-tags-input",function(){
  10. clearTimeout(time1);
  11. });
  12. $(document).on("click",".Hui-tags-input",function(){
  13. $(this).find(".Hui-tags-input").focus();
  14. $(this).find(".Hui-tags-list").slideDown();
  15. });
  16. function gettagval(obj){
  17. var str ="";
  18. var token =$(obj).parents(".Hui-tags").find(".Hui-tags-token");
  19. //alert(token.length)
  20. if(token.length<1){
  21. $(obj).parents(".Hui-tags").find(".Hui-tags-val").val("");
  22. return false;
  23. }
  24. for(var i = 0;i< token.length;i++){
  25. str += token.eq(i).text() + ",";
  26. $(obj).parents(".Hui-tags").find(".Hui-tags-val").val(str);
  27. }
  28. }
  29. $(document).on("keydown",".Hui-tags-input",function(event){
  30. $(this).next().hide();
  31. var v = $(this).val().replace(/\s+/g, "");
  32. var reg=/^,|,$/gi;
  33. v=v.replace(reg,"");
  34. v=$.trim(v);
  35. var token =$(this).parents(".Hui-tags").find(".Hui-tags-token");
  36. if(v!=''){
  37. if(event.keyCode==13||event.keyCode==108||event.keyCode==32){
  38. $('<span class="Hui-tags-token">'+v+'</span>').insertBefore($(this).parents(".Hui-tags").find(".Hui-tags-iptwrap"));
  39. $(this).val("");
  40. gettagval(this);
  41. }
  42. }else{
  43. if(event.keyCode==8){
  44. if(token.length>=1){
  45. $(this).parents(".Hui-tags").find(".Hui-tags-token:last").remove();
  46. gettagval(this);
  47. }
  48. else{
  49. $(this).parents(".Hui-tags").find(".Hui-tags-lable").show();
  50. return false;
  51. }
  52. }
  53. }
  54. });
  55. $(document).on("click",".Hui-tags-has span",function(){
  56. var taghasV = $(this).text();
  57. taghasV=taghasV.replace(/(^\s*)|(\s*$)/g,"");
  58. $('<span class="Hui-tags-token">'+taghasV+'</span>').insertBefore($(this).parents(".Hui-tags").find(".Hui-tags-iptwrap"));
  59. gettagval(this);
  60. $(this).parents(".Hui-tags").find(".Hui-tags-input").focus();
  61. });
  62. $(document).on("click",".Hui-tags-token",function(){
  63. var token =$(this).parents(".Hui-tags").find(".Hui-tags-token");
  64. var it = $(this).parents(".Hui-tags");
  65. $(this).remove();
  66. switch(token.length){
  67. case 1 : it.find(".Hui-tags-lable").show();
  68. break;
  69. }
  70. var str ="";
  71. var token =it.find(".Hui-tags-token");
  72. //alert(token.length)
  73. if(token.length<1){
  74. it.find(".Hui-tags-val").val("");
  75. return false;
  76. }
  77. for(var i = 0;i< token.length;i++){
  78. str += token.eq(i).text() + ",";
  79. it.find(".Hui-tags-val").val(str);
  80. }
  81. });

4.19.2 标签混排效果

HTML代码

  1. <div class="pd-10 tags"> <a href="http://www.h-ui.net/">H-ui前端框架</a> <a href="http://www.h-ui.net/websafecolors.shtml">Web安全色</a> <a href="http://www.h-ui.net/Hui-4.4-Unslider.shtml">jQuery轮播插件</a> <a href="http://idc.likejianzhan.com/vhost/korea_hosting.php">韩国云虚拟主机</a> <a href="http://www.h-ui.net/bug.shtml">IEbug</a> <a href="http://www.h-ui.net/site.shtml">IT网址导航</a> <a href="http://www.h-ui.net/icon/index.shtml">网站常用小图标</a> <a href="http://www.h-ui.net/tools/jsformat.shtml">web工具箱</a> <a href="http://www.h-ui.net/bg/index.shtml">网站常用背景素材</a> <a href="http://www.h-ui.net/yuedu/chm.shtml">H-ui阅读</a> <a href="http://www.h-ui.net/easydialog-v2.0/index.html">弹出层插件</a> <a href="http://www.h-ui.net/SuperSlide2.1/demo.html">SuperSlide插件</a> <a href="http://www.h-ui.net/TouchSlide1.1/demo.html">TouchSlide</a></div>

CSS代码

  1. .tags a{height:26px; line-height:26px;padding-right:6px}
  2. .tags0{}
  3. .tags1{color:#C00; font-size:24px}
  4. .tags2{color:#030; font-size:16px}
  5. .tags3{color:#00F}
  6. .tags4{font-size:16px}
  7. .tags5{color:#C00; font-size:20px}
  8. .tags6{color:#F06 font-size:20px}
  9. .tags7{color:#030; font-weight:bold; font-size:18px}
  10. .tags8{color:#F06; font-weight:bold}
  11. .tags9{color:#C00; font-weight:bold;font-size:16px}
  12. .tags a:hover{color:#F00; text-decoration:underline}

可根据自己的需求对css进行修改

JS代码

引入jQuery

  1. var tags_a = $(".tags a");
  2. tags_a.each(function(){
  3. var x = 9;
  4. var y = 0;
  5. var rand = parseInt(Math.random() * (x - y + 1) + y);
  6. $(this).addClass("tags"+rand)});

注意: 如果页面中引用了h-ui.js,无需重复粘贴上面脚本代码。

4.19.3 tag云标签

Copyright ©2013-2022 H-ui.net All Rights Reserved.
豫ICP备19019279号-1
H-ui只是一个纯web前端的程序,没有后台和数据库,也不提供任何系统代运营服务。所有使用H-ui开发的任何系统版权都归开发者所有,造成的任何损失、不良影响,H-ui均不承担任何法律责任。
未经允许,禁止转载、抄袭、镜像
用心做站,做不一样的站