求评分的JS的实现。。

J2EE 码拜 9年前 (2015-05-10) 1152次浏览 0个评论
 

就是淘宝上类似
给卖家打5个星,4个星的那种效果。。。

20分
<!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>
</head>
<body>

<style>
#QuacorGrading input {
background:transparent url(upload_files/jsimg/grading.png) no-repeat scroll right center;
border:0 none;
cursor:pointer;
height:30px;
width:30px;
padding:0;
vertical-align:middle;}</style>
    <div id="QuacorGrading" style="position:absolute;top:230px; left:150px"><strong>评分</strong>
      <input name="1" type="button" />
            <input name="2" type="button" value="2"/>
            <input name="3" type="button" value="3"/>
            <input name="4" type="button" value="4"/>
            <input name="5" type="button" value="5"/>
            <input name="6" type="button" value="6"/>
            <input name="7" type="button" value="7"/>
            <input name="8" type="button" value="8"/>
            <input name="9" type="button" value="9"/>
            <input name="10" type="button" />
            <span id="QuacorGradingValue"><b><font size="5" color="#fd7d28">6.5</font></b>分</span>
        <script type="text/javascript">
        	var GradList = document.getElementById("QuacorGrading").getElementsByTagName("input");
			for(var di=0;di<parseInt(document.getElementById("QuacorGradingValue").getElementsByTagName("font")[0].innerHTML);di++){GradList[di].style.backgroundPosition = ""left center"";}
			for(var i=0;i < GradList.length;i++){
				GradList[i].onmouseover = function(){
					for(var Qi=0;Qi<GradList.length;Qi++){
						GradList[Qi].style.backgroundPosition = ""right center"";
						}
					for(var Qii=0;Qii<this.name;Qii++){
						GradList[Qii].style.backgroundPosition = ""left center"";
						}
					//alert(GradList.length);
					document.getElementById("QuacorGradingValue").innerHTML = ""<b><font size="5" color="#fd7d28">""+this.name+""</font></b>分"";
					}
				}
        </script>
    </div>
</body></html>
演示:http://www.17sucai.com/pins/demoshow/428
下载:http://www.17sucai.com/pins/428.html
引用 2 楼 huxiweng 的回复:

演示:http://www.17sucai.com/pins/demoshow/428
下载:http://www.17sucai.com/pins/428.html

效率

60分
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

</head>
<body>
	<h1>评分:</h1>
	<table id="rating">
		<tr>
		<td>☆</td>
		<td>☆</td>
		<td>☆</td>
		<td>☆</td>
		<td>☆</td>
		</tr>
	</table>

	<script type="text/javascript">

		var rating=document.getElementById("rating");
		var tds=rating.getElementsByTagName("td");
		for(var i=0;i<tds.length;i++){
				tds[i].onmouseover=function(){
					var index=getIndex(tds,this);
					for(var i=0;i<=index;i++){
						tds[i].innerHTML="★";
					}
				}
				tds[i].onmouseout=function(){
					for(var i=0;i<tds.length;i++){
						tds[i].innerHTML="☆";
					}
				}
				tds[i].style.cursor=""pointer"";
		}

		function getIndex(hc,element){
			for(var i=0;hc.length;i++){
				if(hc[i]==element){
					return i;
				}

			}
			return -1;

		}

	</script>

</body>
</html>

效果:
求评分的JS的实现。。


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明求评分的JS的实现。。
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!