0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

javasript, jquery(テーブルタグ)

Last updated at Posted at 2020-12-21

①html、 javasriptのツールの開発

 →オンラインツールを使えるため、ツールのダウンロードが不要です。
   https://jsfiddle.net/

スクリーンショット 2020-12-21 10.23.23.png

②HTML分にHTMLソースを追加してから、実行する

<html>

  <head>
    <title>Hoge</title>
  </head>

  <body id="main-id">

    <table>
      <tr>
        <td>hoge</td>
      </tr>
    </table>

  </body>

</html>

イメージ
スクリーンショット 2020-12-21 10.40.44.png

③HTMLのかわり、JQUERY(OOP)でページを表示する

 ①HTMLのTABLEがJQUERYのTABLEに変換する
 ②HTMLのTRがJQUERYのTRに変換する
 ③HTMLのTDがJQUERYのTDに変換する


//マインオブジェクト
var $main  = $("#main-id");

//オブジェクトに変換する
var $table = $("<table>");              //テーブルオブジェクト
var $tr    = $("<tr>");                //行オブジェクト
var $td    = $("<td>") .html("hoge");  //カラムオブジェクト

//親オブジェクトに子オブジェクトを追加
$tr.append($td);
$table.append($tr);
$main.append($table);

イメージ
スクリーンショット 2020-12-21 10.59.27.png

④実行した後、HTMLの表示の結果と同じ

スクリーンショット 2020-12-21 11.08.53.png

⑤JQUERY(OOP)のclickのメソッド


var $table = $("<table>"); //テーブルオブジェクト
$table.click(function() {
    //todo
});

var $tr    = $("<tr>"); //行オブジェクト
$tr.click(function() {
    //todo
});

var $td    = $("<td>") .html("hoge"); //カラムオブジェクト
$td.click(function() {
    //todo
});

以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?