zoukankan      html  css  js  c++  java
  • 在js中网页面写入数据时需要注意的几点

    网页代码

    <tbody id="t_gun">
                <s:iterator  value="gunList" status="st">
                    <tr id="init${st.count}"  class="tr_bg1" onMouseOver="this.className='tr_over'" onMouseOut="this.className='tr_bg1'" >
                            <td style="font-weight: bold;color: green; 10%">
                                <s:property value="oilgunno"/>
                            </td>
                            <td style="font-weight: bold;color: green; 13.5%">
                                <s:property value="oilname"/>            
                            </td>
                            <td style="font-weight: bold;color: green; font-size:18px; 16%;" >0</td>
                            <td style="font-weight: bold;color: green; font-size:18px; 10.5%;" >0</td>
                            <td style="font-weight: bold;color: green;  font-size:18px; 13.5%;" >0</td>
                            <td style="font-weight: bold;color: green;  font-size:18px;    13.5%; " >0</td>
                            <td style="font-weight: bold;color: green;  font-size:20px; 12.5%;" >0</td>
                            <td style="font-weight: bold;color: green; 10%;">断开</td>
                            
                    </tr>
                </s:iterator>
                
                </tbody>

    JS代码:

    $("#init"+(i+1)).html('<td style="font-weight: bold;color: red; 10%">'+obj.oilGunno+'</td>'+
    			      '<td style="font-weight: bold;color: red; 13.5%">'+obj.oilName+'</td>'+
    			      '<td style="font-weight: bold;color: red; font-size:18px; 16%;" >'+obj.cardno+'</td>'+
    			      '<td style="font-weight: bold;color: red; font-size:18px; 10.5%;" >'+obj.oilBalance+'</td>'+
    			      '<td style="font-weight: bold;color: red;  font-size:18px; 13.5%;" >'+obj.oilPrice+'</td>'+
    			      '<td style="font-weight: bold;color: red;  font-size:18px; 13.5%; " >'+obj.oilLitter+'</td>'+
    			      '<td style="font-weight: bold;color: red;  font-size:20px; 12.5%;" >'+obj.oilAmount+'</td>'+
    			      '<td style="font-weight: bold;color: red; 10%;">'+obj.statusname+'</td>');

    使用$("#Id").html()的方法往指定id的投入中插入一行数据,里面要注意的就是在.html()中"<td>""</td>"需要用单引号括起来,要不然JS识别不了,而且不会报错。当然用转义字符也可以,不过我闲麻烦,这个比较快;

    下面值转义字符的网址,有兴趣的小伙伴可以去看看

    http://tool.oschina.net/commons?type=2

  • 相关阅读:
    Spring之Redis访问(Spring-data-redis)
    SpringCloud之Hystrix容错保护原理及配置
    SpringCloud之Feign声明式调用原理及配置
    SpringCloud之Ribbon负载均衡配置
    基于Zookeeper实现分布式锁
    SpringCloud之Eureka注册中心原理及其搭建
    SpringBoot定时任务(schedule、quartz)
    Java和操作系统交互(Java 代码是怎么执行)(转)
    深入SpringBoot注解原理及使用
    Spring事务的配置、参数详情及其原理介绍(Transactional)
  • 原文地址:https://www.cnblogs.com/mlorct/p/6651393.html
Copyright © 2011-2022 走看看