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

  • 相关阅读:
    查看电脑保存的wifi密码
    数据仓库
    nodejs 中国汉字模糊查询简单(很low)实现
    nodejs express 框架 上传文件
    async样例
    mongodb Map/reduce测试代码
    未释放资源的教训,开发MongoDB连接一定要关闭连接
    采集系统优化:大家接手过的最烂的项目,最坑爹的项目是哪个?
    Android的HttpClient调用,冲突的解决办法
    MongoDBcrud操作,采集部分代码
  • 原文地址:https://www.cnblogs.com/mlorct/p/6651393.html
Copyright © 2011-2022 走看看