J'essaie d'ajouter un bouton "supprimer" à ul éléments sur le vol stationnaire. Cela semble fonctionner, mais je n'arrive pas à aligner le bouton sur la droite de l'écran. Chaque fois que j'essaie, il semble aller à droite et en bas d'une ligne.Ajout d'un bouton
Voici le script complet:
<!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>
EDIT 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>
EDIT 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>
veuillez poster votre css car cela causera le problème. Ma première pensée est que vous avez affichage: bloc envoyé sur votre s. Notez que vous pouvez inclure un espace entre les ancres – lnrbob
Cette page n'a pas de css pour le moment. Le script ci-dessus est tout et je suis en train de tester IE8. – oshirowanen
Cela fonctionne pour moi: http://www.jsfiddle.net/txqhB/ vous pouvez avoir CSS supplémentaire. (Je l'ai testé sur chrome et IE7) – Shikiryu