dow46218 2014-10-20 05:30
浏览 49
已采纳

将css和js导入PHP codeigniter

So, Everything works fine in my HTML

<style>
   #draggable { width: 90px; height: 90px; }
   #draggable2 { width: 90px; height: 90px; }
   #draggable3 { width: 90px; height: 90px; }
   #draggable4 { width: 90px; height: 90px; }
   #draggable5 { width: 90px; height: 90px; }
   #draggable6 { width: 90px; height: 90px; }
   #draggable7 { width: 90px; height: 90px; }
   #draggable8 { width: 90px; height: 90px; }
   #draggable9 { width: 90px; height: 90px; }
   #draggable10 { width: 90px; height: 90px; }
</style>
<script>
    $(function() {
       $( "#draggable" ).draggable();
       $( "#draggable2" ).draggable();
       $( "#draggable3" ).draggable();
       $( "#draggable4" ).draggable();
       $( "#draggable5" ).draggable();
       $( "#draggable6" ).draggable();
       $( "#draggable7" ).draggable();
       $( "#draggable8" ).draggable();
       $( "#draggable9" ).draggable();
       $( "#draggable10" ).draggable();
    });
 </script>

And here is the body:

<body>
     <div id="draggable" class="ui-widget-content">
         <a class="btn btn-info btn-xs" href="hall_a.html" role="button">Proceed</a>
     </div> <br>
     <div id="draggable2" class="ui-widget-content">
         <a class="btn btn-info btn-xs" href="hall_a.html" role="button">Proceed</a>
     </div> <br>
     <div id="draggable3" class="ui-widget-content">
         <a class="btn btn-info btn-xs" href="hall_a.html" role="button">Proceed</a>
     </div> <br>
     <div id="draggable4" class="ui-widget-content">
         <a class="btn btn-info btn-xs" href="hall_a.html" role="button">Proceed</a>
     </div> <br>
     <div id="draggable5" class="ui-widget-content">
         <a class="btn btn-info btn-xs" href="hall_a.html" role="button">Proceed</a>
     </div> <br>
     <div id="draggable6" class="ui-widget-content">
         <a class="btn btn-info btn-xs" href="hall_a.html" role="button">Proceed</a>
     </div> <br>
     <div id="draggable7" class="ui-widget-content">
         <a class="btn btn-info btn-xs" href="hall_a.html" role="button">Proceed</a>
     </div> <br>
     <div id="draggable8" class="ui-widget-content">
         <a class="btn btn-info btn-xs" href="hall_a.html" role="button">Proceed</a>
     </div> <br>
     <div id="draggable9" class="ui-widget-content">
         <a class="btn btn-info btn-xs" href="hall_a.html" role="button">Proceed</a>
     </div> <br>
     <div id="draggable10" class="ui-widget-content">
         <a class="btn btn-info btn-xs" href="hall_a.html" role="button">Proceed</a>
     </div> <br>
</body>

My Question is: How to do that in my CodeIgniter:

This is my view in my CodeIgniter:

<head>
    <style>
        #draggable { width: 90px; height: 90px; }
        #draggable2 { width: 90px; height: 90px; }
        #draggable3 { width: 90px; height: 90px; }
        #draggable4 { width: 90px; height: 90px; }
        #draggable5 { width: 90px; height: 90px; }
        #draggable6 { width: 90px; height: 90px; }
        #draggable7 { width: 90px; height: 90px; }
        #draggable8 { width: 90px; height: 90px; }
        #draggable9 { width: 90px; height: 90px; }
        #draggable10 { width: 90px; height: 90px; }
    </style>

    <script>
        $(function() {
            $( "#draggable" ).draggable();
            $( "#draggable2" ).draggable();
            $( "#draggable3" ).draggable();
            $( "#draggable4" ).draggable();
            $( "#draggable5" ).draggable();
            $( "#draggable6" ).draggable();
            $( "#draggable7" ).draggable();
            $( "#draggable8" ).draggable();
            $( "#draggable9" ).draggable();
            $( "#draggable10" ).draggable();
        });
    </script></head>

<body>
<?php
  if(is_array($posting)){ //This function is purposed to retrieve from Daabase 
    echo '<ol>';
    foreach($posting as $key){
    $judul = '<div id="draggable" class="ui-widget-content">'.$key->tbl_name.'</div>';
    echo $judul;
  }
  echo '</ol>';
}</body>

But now it's only work for 'draggable' only. How to do it for 'draggable2' - 'draggable10'?

  • 写回答

2条回答 默认 最新

  • duan39779 2014-10-20 05:32
    关注

    You have to give the id with increments like

    echo '<ol>';
    $i = 1;
    foreach($posting as $key){
        $judul = '<div id="draggable'.$i++.'" class="ui-widget-content">'.$key->tbl_name.'</div>';
        echo $judul;
    }
    

    And just change the first draggable from

    $( "#draggable" ).draggable();
    

    to

    $( "#draggable1" ).draggable();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了