我想製作一個Jquery腳本,如果它溢出#box
div之外,將在文本週圍放置標籤標籤。文本顯然比30px寬,而div確實隱藏了大部分文本。我的問題是沒有出現選取框效果。這裏是我的完整代碼:當文本溢出時製作JQuery字幕
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
#box {
width:30px;
overflow:hidden;
}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>
<body>
<div id="box">
Overflooooooooooow
</div>
<script>
$(function(){
$box = $('#box');
$box.children().each(function(){
if ($box.width() < $(this).width()) {
$(this).wrap('<marquee>');
}
});
});
</script>
</body>
</html>
謝謝你的幫助。所有的幫助表示讚賞。
_「另請注意,最喜歡的jQuery方法,。孩子()不返回文本節點,讓所有的孩子,包括文字和註釋節點,用.contents()」 _ – j08691