私はtextareaとdivを持っています。2つのHTMLコンポーネントを重ねて表示する
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<script type="text/javascript" src="JSFile.js"></script>
<style type="text/css">
.hidden {visibility: hidden;}
</style>
</head>
<body>
<textarea id="txtArea" onmouseover="mouseMoved();"></textarea>
<div id="hiddenDiv" class="hidden"></div>
</body>
テキストエリアに関連付けられているのonmouseoverイベントがあります。
function mouseMoved() {
var txtArea = document.getElementById("txtArea");
var hiddenDiv = document.getElementById("hiddenDiv");
var newHtml = "";
var words=txtArea.value.split(" ");
for (i = 0; i < words.length; i++) {
newHtml += '<span>' + words[i] + '</span> ';
}
hiddenDiv.innerHTML=newHtml;
}
textarea
に同じ層にhiddenDiv
を配置する方法はありますか?私がすることを目的とは何
ユーザーがtextarea
の上にマウスと同様にdiv
を移動すると、そのイベントが伝える、マウスポインタの下の語が何であるように、div要素のspan
秒でイベントを添付することです。私は私の問題をはっきりと表したいと思います。もっと知りたいのであれば、私は情報を提供します。
ありがとうございます。
編集:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<script type="text/javascript" src="JSFile.js"></script>
<style type="text/css">
.hidden {
position: relative;
/*visibility: hidden;*/
top: -50px;
left: 5px;
z-index: -1;
}
.txtArea {
position: relative;
}
</style>
</head>
<body>
<textarea id="txtArea" class="txtArea" onmouseover="mouseMovedOnTextBox();"></textarea>
<div id="hiddenDiv" class="hidden"></div>
<label id="lbl"></label>
</body>
との.js:
function mouseMovedOnTextBox() {
var txtArea = document.getElementById("txtArea");
var hiddenDiv = document.getElementById("hiddenDiv");
var newHtml = "";
var words=txtArea.value.split(" ");
for (i = 0; i < words.length; i++) {
newHtml += '<span onmouseover="mouseMovedOnSpan(\'' + words[i] +'\');">' + words[i] + '</span> ';
}
hiddenDiv.innerHTML=newHtml;
}
function mouseMovedOnSpan(word) {
document.getElementById("lbl").innerHTML=word;
}
このページをチェックアウト:http://www.vinylfox.com/forwarding-mouse-eventsthrough-throughers/ –