我有这个代码,它动态显示文档'div'中输入字段的值。 我已经设置了'div'max-width属性,但它看起来像只在输入字符串内有空格时才起作用,如果没有'div'字符串中的字符串可以继续并且继续。在一行中。 我该如何解决这个问题?动态输入最大宽度
<!DOCTYPE html>
<html>
<head>
<style>
div {
max-width: 300px;
font-size:40px;
color:red;
font-weight:bold;
background-color:yellow;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("input").keyup(function(){
$("div").text($("input").val());
});
});
</script>
</head>
<body>
Sample value: <input type="text">
<div></div>
</body>
</html>
可能的重复https://stackoverflow.com/questions/1147877/how-to-word-wrap-text-in-html –