因此,我尝试在以下代码中获取变量y
和myElement
,以确定具有类undefined
的图像的位置。单击它时,应将顶部和左侧样式设置为变量所在的位置(光标位置)。当我测试它时,它默认为<!doctype html>
<html>
<body onclick="getCoord(event)" style="height:2000px;">
<h2>click</h2>
<p id="display"></p>
<script>
function getCoord(event) {
var x = event.clientX;
var y = event.clientY;
var coord = "x:" + x + "y:" + y;
document.getElementById("display").innerHTML = coord;
console.log(x);
console.log(y);
document.getElementById('myElement').style.position = "absolute";
document.getElementById('myElement').style.top = y; //or whatever
document.getElementById('myElement').style.left = x; // or whatever]
};
</script>
<img id="myElement" src="https://picturethismaths.files.wordpress.com/2016/03/fig6bigforblog.png?w=419&h=364">
</body>
</html>
。
ind = find(~Population); % find zero places
Population(ind) = randi(4,1,length(ind)); % replace them with a random integer
答案 0 :(得分:0)
您忘记添加the measurement数字将被解释为。
<!DOCTYPE html>
<html>
<body onclick="getCoord(event)" style="height:2000px;">
<h2>click</h2>
<p id="display"></p>
<script>
function getCoord(event) {
var x = event.clientX;
var y = event.clientY;
var coord = "x:" + x + " y:" + y;
document.getElementById("display").innerHTML = coord;
console.log(x);
console.log(y);
var myEle = document.getElementById('myElement'); // no need to use 3 times
myEle.style.position = "absolute";
myEle.style.top = y + "px"; // plus "px"
myEle.style.left = x + "px"; // plus "px"
};
</script>
<img id="myElement" src="https://picturethismaths.files.wordpress.com/2016/03/fig6bigforblog.png?w=419&h=364">
</body>
</html>
&#13;