你好,我有以下代码,需要能够将两个元素定位在容器中包含的框 (#third) 中。请提供两个元素定位的代码。我需要定位以下元素(请参阅以下行)
append('$${t}^x\sqrt{t}^x$$'); and
append('<label>Filename:</label> <input type="text" name="file" id="file" />');
<!-- saved from url=(0022) -->
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest /MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}
//ev.target.id this gives us the id of the symbol being dragged
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
//ev.target.appendChild(document.getElementById(data));
switch(data)
{
case("drag8"):
$('#second').append('$${t}^x\sqrt{t}^x$$');
$('#container').append('<div id="third" ondrop="drop(event)" ondragover="allowDrop(event)"></div>');
$('#third').append('$${t}^x\sqrt{t}^x$$');
$('#third').append('<label>Filename:</label> <input type="text" name="file" id="file" />');
break;
default:
}
MathJax.Hub.Queue(["Typeset",MathJax.Hub,"second"]);
MathJax.Hub.Queue(["Typeset",MathJax.Hub,"third"]);
}
</script>
<style>
#header {
width: 100%;
background-color: white;
height: 30px;
}
#container {
width: 600px;
height:1500px
background-color: #ffffff;
margin: auto;
}
#first {
width: 100px;
border: 2px solid black;
float: left;
height: 400px;
}
#second {
width: 300px;
border: 2px solid black;
top:0;
float: right;
height: 100px;
}
#third {
position: absolute;
top: 180px;
border: 2px solid black;
right:430px;
width: 200px;
height: 100px;
}
#third .power1{
width: 20px;
height: 10px;
float: left;
border: 2px solid black;
}
#clear {
clear: both;
}
</style>
</head>
<body>
<div id="header"></div>
<div id="container">
<div id="first">
<span id="drag8" style="text-decoration:overline;" draggable="true" ondragstart="drag(event)" >$${t}^x\sqrt{t}^x$$</span>
</div>
<div id="second" ondrop="drop(event)" ondragover="allowDrop(event)"> </div>
<div id="clear"></div>
</div>
</body>
最佳答案
合并 3 个追加
$('#container').append('<div id="third" ondrop="drop(event)" ondragover="allowDrop(event)">$${t}^x\sqrt{t}^x$$<label>Filename:</label> <input type="text" name="file" id="file" /></div>');
关于javascript - 如何使用 JQuery 在框中定位以下元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38559845/