我想追加一個「刪除」按鈕懸停的ul項。它似乎工作,但我似乎無法讓按鈕對齊到屏幕的右側。每次我嘗試時,似乎都往右下一行。追加按鈕
以下是完整的腳本:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>remove button</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("li").hover(
function() {
$(this).append($("<a href='#'>(remove)</a>"));
},
function() {
$(this).find("a:last").remove();
}
);
});
</script>
</head>
<body>
<ul id="mylist">
<li id="item_4"><a href="http://www.google.com">google</a></li>
<li id="item_9"><a href="http://www.yahoo.com">yahoo</a></li>
<li id="item_2"><a href="http://www.bing.com">bing</a></li>
<li id="item_5"><a href="http://www.youtube.com">youtube</a></li>
<li id="item_8"><a href="http://www.ebay.com">ebay</a></li>
</ul>
</body>
</html>
編輯1:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>remove button</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<style type="text/css">
li a.button {float:right;}
</style>
<script>
$(document).ready(function() {
$("li").hover(
function() {
$(this).append($(" <a href='#' class='button'>(remove)</a>"));
},
function() {
$(this).find("a:last").remove();
}
);
});
</script>
</head>
<body>
<ul id="mylist">
<li id="item_4"><a href="http://www.google.com">google</a></li>
<li id="item_9"><a href="http://www.yahoo.com">yahoo</a></li>
<li id="item_2"><a href="http://www.bing.com">bing</a></li>
<li id="item_5"><a href="http://www.youtube.com">youtube</a></li>
<li id="item_8"><a href="http://www.ebay.com">ebay</a></li>
</ul>
</body>
</html>
編輯2:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>remove button</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<style type="text/css">
a.button {float:right;}
</style>
<script>
$(document).ready(function() {
$("li").hover(
function() {
$(this).append($(" <a href='#' class='button'>(remove)</a>"));
},
function() {
$(this).find("a:last").remove();
}
);
});
</script>
</head>
<body>
<ul id="mylist">
<li id="item_4"><a href="http://www.google.com">google</a></li>
<li id="item_9"><a href="http://www.yahoo.com">yahoo</a></li>
<li id="item_2"><a href="http://www.bing.com">bing</a></li>
<li id="item_5"><a href="http://www.youtube.com">youtube</a></li>
<li id="item_8"><a href="http://www.ebay.com">ebay</a></li>
</ul>
</body>
</html>
請張貼您的CSS,因爲這將導致問題。我的第一個想法是,你有 s發送的display:block。請注意,您可能希望在錨點之間包含空格 – lnrbob 2010-12-15 11:37:39
此頁面暫時沒有css。上面的腳本是一切,我正在測試IE8。 – oshirowanen 2010-12-15 11:38:48
它適用於我:http://www.jsfiddle.net/txqhB/你可能有額外的CSS。 (我在Chrome和IE7上測試過它) – Shikiryu 2010-12-15 11:49:51