拼接的按钮没有样式,需要使用

var str = $("<a href='javascript:void(0)' class='easyui-linkbutton' onclick='delDeviceInfo(this)' style='margin-top:2px;height:25px;width:25px;color:#fff;border:none;background:#63B8FF'>-</a>").appendTo($(".deviceView"))
$.parser.parse(str);

在JavaScript中一些dom元素是动态拼接的,由于页面实在加载完成后执行的js,页面已经渲染完成,所以没有加载到动态添加的组件的easui样式,所以需要手动执行渲染某个部件或者整个页面。

Parser(解析器)

解析器是easy ui很重要的基础组件,在easy ui中我们可以简单的通过class定义一个组件,通过parser进行解析,从而达到很好的交互效果。

parser会获取全部在指定内定为为easy ui组件的class定义,而且依据后缀定义把当前节点解析渲染成特定的组件。

$.parser.parse();      //解析EasyUI组件

附加:做如下的效果,点击加号增加一行,点击减号删除一行。

代码:

html:

<div>
<table class='table' cellpadding="0" cellspacing="0" border="0" style='margin:0'>
<tbody class='deviceView'>
<tr class='firstChild'>
<td width="114" class="labelName" style='color:red'>设备</td>
<td width="280">
<input type="hidden" id="" />
<select id="" class="form-control input-sm">
<option selected>GZGY-PB-CMNET-RT04-HX/NE5000E</option>
</select>
</td>
<td class="labelName" style='width:75px'>层级<span style='color:red;font-weight:normal;padding:0 5px;'>PM</span></td>
<td class="labelName" style='color:red;min-width:25px!important;padding-left:0;'>模板</td>
<td width="140">
<select class="form-control input-sm">
<option selected>PM通用模板</option>
<option selected>PM通用模板</option>
<option selected>PM通用模板</option>
</select>
</td>
<td>
<a href="javascript:void(0)" class="easyui-linkbutton " onclick="addDeviceInfo()" style="margin-top:2px;height:25px;width:25px;color:#fff;border:none;background:#63B8FF">+</a>
</td>
</tr>
</tbody>
</table>
</div>

JS:

//新增设备,通过tr长度赋值id
function addDeviceInfo(){
var i = $(".deviceView tr").length+1;
var str = $("<tr data-id='"+($(".deviceView tr").length+1)+"' id='deviceInfo"+($(".deviceView tr").length+1)+"'><td width='104' style='font-weight:900;text-align: right;line-height: 31px;'>设备</td><td width='280'><input type='hidden'/><select id='device"+($(".deviceView tr").length+1)+"' class='deviceAdd easyui-combobox' style='width:280px'></select>"+
"</td><td class='labelName' style='width:75px'>层级<span style='text-align: left;color:red;font-weight:normal;padding:0 5px;display:inline-block;width:30px;' id='lev"+($(".deviceView tr").length+1)+"'></span></td><td width='40' style='line-height: 32px;font-weight:900;text-align: right;padding-left:0;'>模板</td>"+
"<td width='140'><select id='temp"+($(".deviceView tr").length+1)+"' class='easyui-combobox tempAdd' style='width:140px'></select></td>"+
"<td><a href='javascript:void(0)' class='easyui-linkbutton' onclick='delDeviceInfo(this)' style='margin-top:2px;height:25px;width:25px;color:#fff;border:none;background:#63B8FF'>-</a></td></tr>").appendTo($(".deviceView"));
$.parser.parse(str);
initDeviceList("device"+i);
initTemp("temp"+i);
}
//删除设备,找到按钮的父亲节点的父亲节点,及tr,然后删除
function delDeviceInfo(e){
$(e).parent().parent().remove();
}

 

easyUI在使用字符串拼接时样式不起作用,点击加号增加一行,点击减号删除一行效果。的更多相关文章

  1. [转]easyui常用控件及样式API中文收藏

    [转]easyui常用控件及样式收藏 2013-05-06 23:01 30612人阅读 评论(0) 收藏 举报  分类: java ee(5)  目录(?)[+] CSS类定义: div easyu ...

  2. C# 字符串拼接性能探索 c#中+、string.Concat、string.Format、StringBuilder.Append四种方式进行字符串拼接时的性能

    本文通过ANTS Memory Profiler工具探索c#中+.string.Concat.string.Format.StringBuilder.Append四种方式进行字符串拼接时的性能. 本文 ...

  3. C++在字符串前加一个L作用:

    在字符串前加一个L作用:    如 L"我的字符串" 表示将ANSI字符串转换成unicode的字符串,就是每个字符占用两个字节.    strlen("asd" ...

  4. css样式实现字体删除线效果

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  5. css样式表。作用是美化HTML网页.

    样式表分为:(1)内联样式表 和HTML联合显示,控制精确,但是可重用性差,冗余多. 如:<p style="font-size:10px">内联样式表</p&g ...

  6. 在用easyui中做CRUD功能时,当删除一行或多行数据后再点击修改会提示你选中了多行,如何解决这个bug了?

    在用easyui中做CRUD功能时,当删除一行或多行数据后再点击修改会提示你选中了多行,如何解决这个bug了? 在删除成功后,加上这句话就可以了:$("#dg").datagrid ...

  7. Angular中innerHTML标签的样式不起作用详解

    1.背景 在最近angular的项目中,需要用到[innerHTML]标签来指定一个div的样式: //HTML部分 <div class="contents" [inner ...

  8. 微信小程序子组件样式不起作用的解决办法

    今天我在编写微信小程序项目时,发现父组件引用子组件过后,子组件的样式不起作用,在上网查了很多解决办法后,成功解决了这一问题. 解决办法: 1.在全局样式文件app.wxss中引入子组件的样式,如 @i ...

  9. vue点击切换样式,点击切换地址栏,点击显示或者隐藏

    1. vue点击显示切换 :class='{"span":index==0}' class原本是 类选择器 加上 :class就是绑定属性的意思 '{"span" ...

随机推荐

  1. vue 配置页面动态的 title

  2. [luogu3203 HNOI2010] 弹飞绵羊 (分块)

    传送门 Description 某天,Lostmonkey发明了一种超级弹力装置,为了在他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置, ...

  3. Problem 3

    Problem 3 # Problem_3.py """ The prime factors of 13195 are 5, 7, 13 and 29. What is ...

  4. SpringBoot 国际化

    一.配置文件 二.application.properties 文件( 让国际化的文件被 SpringBoot 识别 ) spring.messages.basename=i18n.login 三.h ...

  5. 关于excel导出

    转载自:https://blog.csdn.net/ljj_9/article/details/50395688 //一个excel表格: HSSFWorkbook wb = new HSSFWork ...

  6. unity3d 中动画的帧事件

    代码事件监听 using UnityEngine; using System.Collections; public class BoxEventScript : MonoBehaviour { vo ...

  7. 页面与后台传递中文乱码问题(java乱码)

    1.前台中文传递到后台乱码. 前台不须要处理, 系统一般都会默认把中文转化为ISO-8859-1类型. 仅仅需在后台接受数据是处理 Str为前台传过来的中文字符串: String inputer = ...

  8. iOS推送 (百度推送)

    近期在使用推送,所以与大家分享一下我所遇到的问题,与解决这个问题的方法.! 1.首先生成CertificateSigningRequest文件. 点击钥匙串訪问-->从证书颁发机构请求证书--& ...

  9. IOS开发教程--怎样使用点9图片

    事先准备一张图片: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA== ...

  10. 刚接触Joomla,写一下瞎折腾的初感受~

    我这几天一直在苦苦寻找一款能够长期投靠的CMS产品,要求的是 1)必须支持命名空间 2)必须OOP + MVC分层 3)丰富分文档和使用群体,至少是出名的.免得哪一天他们解散了 4)-- 一開始我把目 ...