duandunzhuo3234 2013-10-05 22:19
浏览 30
已采纳

用Javascript追加建立一个列表

I want to build a list with a Javascript that uses Append function.

I have a index.php file, script.js file and a search.php file that makes the mysql query.

I got it all to work but the layout is not the best. So i wounder how to make the layout better.

I want it to be displayed as a list this should be done with CSS or table?

Right now it just shows up like this 414622570992222

this.number=70992222 this.code=4146225

So what i want it to like like is a list without boarders like this (but no borders).

----------------------
| Number   | Code    |
----------------------
| 70992222 | 4146225 |
----------------------

Here is some code from my script.js file.

$.each(data.results, function(){
                        //Give the list element a rel with the data results ID incase we want to act on this later, like selecting from the list

                        $('#results-list').append("<li rel='" + this.number + "'>" + this.code + this.number + "</li>");

And this is the display line in my index.php file

        <div id='results-holder'>


            <ul id='results-list'>
  • 写回答

3条回答 默认 最新

  • dra87370 2013-10-05 22:36
    关注

    replace your ul tag with a table

    <table id='results-list'></table>
    

    then append table headings and rows to your table with jquery.

    $('#results-list').append("<tr><th>number</th><th>code</th></tr>"); 
    $('#results-list').append("<tr><td>"+ this.number + "</td><td>" + this.code + "</td></tr>");
    

    more info about html tables can be found here:

    http://www.w3schools.com/html/html_tables.asp

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测