<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {
border: 1px solid black;
background-color: lightblue;
width: 150px;
white-space: nowrap;
overflow: hidden;
text-overflow: visible;
}
</style>
</head>
<body>
<h1>使用 JavaScript 更改文本溢出</h1>
<p>单击“试一试”按钮更改 DIV 元素的 text-overflow 属性:</p>
<button onclick="myFunction()">试一试</button>
<div id="myDIV">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
</div>
<script>
function myFunction() {
document.getElementById("myDIV").style.textOverflow = "ellipsis";
}
</script>
</body>
</html>