我有以下功能需要打印以给定点(x,y )为中心的动态生成的文本( txt)
function printText(x,y,txt) {
var s = "";
s = "<b style=???>"+txt+"</b>";
document.getElementById("some_div").innerHTML = s;
}
我怎样才能做到这一点?
我有以下功能需要打印以给定点(x,y )为中心的动态生成的文本( txt)
function printText(x,y,txt) {
var s = "";
s = "<b style=???>"+txt+"</b>";
document.getElementById("some_div").innerHTML = s;
}
我怎样才能做到这一点?
制作position
divrelative
并在内部元素上使用absolute
定位,如下所示:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<title>Test</title>
<meta charset="UTF-8" />
<style>
#some_div {
postion:relative;
height:300px;
}
#some_div b {
position:absolute;
}
</style>
<script>
function printText(x, y, txt) {
var s = "<b style=\"left:" + x + "px;top:" + y + "px;\">"+txt+"</b>";
document.getElementById("some_div").innerHTML = s;
}
</script>
</head>
<body>
<div id="some_div"></div>
<button onclick="printText(100, 40, 'This is a test');">Click Me</button>
</body>
</html>