編集2 -jsfiddleを使用して簡単な例を作成することにしました。
ご覧のとおり、私は新しいdivを参照しようとしています。
編集-d/t反対票と不明確な質問
私は次のようなリンクリストを持っています:
var struct_list = function () {
this.id = 0;
this.name = 0;
this._head = null;
};
struct_list.prototype = {
// .. adding code , delete code ...
list_contents: function () {
var current = this._head;
while ( current != null ) {
var div = document.createElement("div");
div.style.width = "100px";
div.style.height = "100px";
div.style.background = "white";
div.style.color = "black";
div.style.top = "0px";
div.style.left = "0px";
div.style.margin = "400px 1000px auto";
div.style.cursor = "pointer";
div.innerHTML = current.name;
div.onclick = function ( v ) { var d = document.getElementById('div'); alert(d)};
document.body.appendChild(div);
current = current.next;
}
return null;
},};
このリンクリストを表示できるようにしたいのですが、表示された各アイテムは「オンクリック」と対話できるようになっています。
例:
struct_list.add ( 0 , "Zero" );
struct_list.add ( 1 , "One" );
struct_list.list_contents();
_________________________________________________________________________
| |
| <clickable> "Zero" that does a function(id) that passes over its ID(0) |
|________________________________________________________________________|
| |
| <clickable> "One" <same as above> |
|________________________________________________________________________|
不明な点がありましたらごめんなさい。それでも不明な場合は再編集します。謝罪いたします。
データを保持するリンクリスト構造体があり(データは頻繁に変更されます)、データを更新するためのsetIntervalがあります。私の質問は、公開されたコンテンツをクリックしながら構造体のコンテンツを一覧表示するにはどうすればよいですか。リンクリストの各コンテンツにIDが含まれるように設定しました。また、y軸のオーバーフローが自動的に行われるようにするにはどうすればよいですか?私はそれを有効にしているdivに配置する必要があると推測しています。
しかし、私の本当の質問は、リンクリスト要素を公開すると同時に、onclickを介してそれらと対話できるようにする方法です。
また、純粋なjavascript以外は使用したくありません。
(私の考えでは)例はおそらく次のようになります:
<div id="PopUp">
<script>
setInterval(function() {
if ( struct_qued_list ) {
struct_qued_list = false;
main.struct_list.list_contents(); // the linked list
}
}, 100);
</script>
</div>
list_contents: function () {
var current = this._head;
while ( current != null ) {
var div = document.createElement("div");
div.style.width = "100px";
div.style.height = "100px";
div.style.background = "white";
div.style.color = "black";
div.style.top = "0px";
div.style.left = "0px";
div.style.margin = "400px 1000px auto";
div.style.cursor = "pointer";
div.innerHTML = current.name;
div.onclick = function ( v ) { var d = document.getElementById('div'); alert(d)};
document.body.appendChild(div);
current = current.next;
}
return null;
},
これを行うためのヘルプまたは論理的な方法をいただければ幸いです。