【问题标题】:Transform an option list into stars将选项列表转换为星号
【发布时间】:2014-01-23 21:08:31
【问题描述】:

我正在使用这部分代码来评价我从 MySQL 形成的一些文章。评分是在我的选项列表中完成的,有人可以用数字 1、2、3 对它们进行评分。有可能以某种方式将此列表转换为 3 星(带有单选按钮、图像或其他东西)?

<form id="ratethis-<?=$PK?>" action="rate.php?idP=<?=$idPK?>"method="post">
 <select name="rating">

 <option value="1">1</option>
 <option value="2">2</option>
 <option value="3">3</option>
 </select> <br> 
 <input type="submit" value="Rate this!"/><br><br>
 </form>

【问题讨论】:

标签: html css


【解决方案1】:

在 html 上:

<ul class="rating">
<span class="strong"><strong><li class="one"><a href="#">1 Star</a></li></strong></span>
<span class="strong"><strong><li class="two"><a href="#">2 Stars</a></li></strong></span>
<span class="strong"><strong><li class="three"><a href="#">3 Stars</a></li></strong></span>
<span class="strong"><strong><li class="four"><a href="#">4 Stars</a></li></strong></span>
<span class="strong"><strong><li class="five"><a href="#">5 Stars</a></li></strong></span>
</ul>

在 CSS 上:

.rating {

margin: 0;

padding: 0;

list-style: none;

clear: both;

width: 75px;

height: 15px;

background-image: url(stars.gif);

background-repeat: no-repeat;

position: relative;

}

.rating li {

text-indent: −9999em;

float: left; /* for IE6 */

}

.rating li a {

position: absolute;

top: 0;

left: 0;

z-index: 20;

height: 15px;

width: 15px;

display: block;

}

.rating .one a {

left: 0;

}

.rating .two a {

left: 15px;

}

.rating .three a {

left: 30px;

}

.rating .four a {

left: 45px;

}

.rating .five a {

left: 60px;

}

也许这个链接会有所帮助:

How to create a star ranking system using css

【讨论】:

  • 仅链接的答案在 SO 上不受欢迎。您应该在您的答案中发布该文章中的相关代码 sn-ps 并适当地引用它们。
  • 哦,抱歉,这是新内容。我认为复制和粘贴是没用的。编辑。
【解决方案2】:

是的,有很多选择:

  1. 只需使用 oldskool 链接:

    <a href="rate.php?idP=<?php echo $idPK; ?>&rating=1"><img src="star.jpg" /></a>
    <a href="rate.php?idP=<?php echo $idPK; ?>&rating=2"><img src="star.jpg" /></a>
    <a href="rate.php?idP=<?php echo $idPK; ?>&rating=3"><img src="star.jpg" /></a>
    

    请确保您从 $_GET 而不是 $_POST 获得评分

  2. 使用javascript(本例中为jquery):

    <img src="star.gif" class="rating" rel="1" />
    <img src="star.gif" class="rating" rel="1" />
    <img src="star.gif" class="rating" rel="1" />
    
    $('.rating').on('click', function() {
        $.post('rate.php?idP=<?php echo $idPK; ?>', {rating: $(this).attr('rel') }, function() { alert('rating saved'); }
    });
    
  3. 发挥创意并发布一些代码

【讨论】:

    猜你喜欢
    • 2021-03-26
    • 2011-02-03
    • 1970-01-01
    • 2019-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多