【学艺不精系列】简单的 JavaScript 表示星级的页面控件脚本
2012-06-12 17:26
483 查看
效果图:
表单名称:Importance,类型为字符串,默认值 '☆☆☆☆☆'
使用方法:
引用此脚本,为容器设置id='selStar',容器最好是span,放在页面需要的位置。
JavaScript脚本:
表单名称:Importance,类型为字符串,默认值 '☆☆☆☆☆'
使用方法:
引用此脚本,为容器设置id='selStar',容器最好是span,放在页面需要的位置。
JavaScript脚本:
/// <reference path="jquery-1.4.1.js" /> /// <reference path="jquery-1.4.1-vsdoc.js" /> $().ready(function () { $("#selStar").css("cursor", "pointer"); $("#selStar").html('<span id="star0">☆</span><span id="star1">☆</span><span id="star2">☆</span><span id="star3">☆</span><span id="star4">☆</span>' + '<input type="hidden" name="Importance" id="importance" value="☆☆☆☆☆" />'); var s0 = 0; var s1 = 0; var s2 = 0; var s3 = 0; var s4 = 0; $("#star0").mouseover(function () { s0 = 1; fnStar(); }); $("#star1").mouseover(function () { s1 = 1; fnStar(); }); $("#star2").mouseover(function () { s2 = 1; fnStar(); }); $("#star3").mouseover(function () { s3 = 1; fnStar(); }); $("#star4").mouseover(function () { s4 = 1; fnStar(); }); $("#star0").mouseout(function () { s0 = 0; fnStar(); }); $("#star1").mouseout(function () { s1 = 0; fnStar(); }); $("#star2").mouseout(function () { s2 = 0; fnStar(); }); $("#star3").mouseout(function () { s3 = 0; fnStar(); }); $("#star4").mouseout(function () { s4 = 0; fnStar(); }); $("#star0").click(fnClick); $("#star1").click(fnClick); $("#star2").click(fnClick); $("#star3").click(fnClick); $("#star4").click(fnClick); function fnStar() { if (s0 + s1 + s2 + s3 + s4 == 0) { var s = $("#importance").val().split(''); $("#star0").text(s[0]); $("#star1").text(s[1]); $("#star2").text(s[2]); $("#star3").text(s[3]); $("#star4").text(s[4]); } else { $("#star0").text("☆"); $("#star1").text("☆"); $("#star2").text("☆"); $("#star3").text("☆"); $("#star4").text("☆"); if (s0 + s1 + s2 + s3 + s4 > 0) { $("#star0").text("★"); } if (s1 + s2 + s3 + s4 > 0) { $("#star1").text("★"); } if (s2 + s3 + s4 > 0) { $("#star2").text("★"); } if (s3 + s4 > 0) { $("#star3").text("★"); } if (s4 > 0) { $("#star4").text("★"); } } } function fnClick() { $("#importance").val($("#star0").text() + $("#star1").text() + $("#star2").text() + $("#star3").text() + $("#star4").text()); } });
相关文章推荐
- 这是梅花雨做的一个日历 Javascript 页面脚本控件,适用于微软的 IE (5.0以上)
- 日历 Javascript 页面脚本控件
- 如何使用WebBrowser控件执行页面的JavaScript脚本,WebBrowser执行JavaScript脚本
- 页面使用Ajax控件,后台不能调用前台Javascript脚本弹出消息框的解决办法
- 梅花雨做的一个日历 Javascript 页面脚本控件
- 关于用户自定义控件与引用该控件的页面之间的javascript脚本冲突
- JS脚本文件的位置对页面加载性能影响以及无阻塞脚本(javascript)模式
- 向Asp.net页面添加javascript脚本
- 用JavaScript脚本实现Web页面信息交互
- select标签,不需要javascript,jquery等控件,自身多项选中简单代码
- javascript模式窗口中如何获取和设置父页面中控件
- JavaScript验证页面控件值时的提示信息的定位
- JavaScript脚本代码的位置及在页面中的执行顺序
- ASP.NET AJAX入门系列(6):UpdateProgress控件简单介绍
- 如何在页面中引用JavaScript脚本?
- 编写服务器控件时,向页面写入脚本的方法
- Javascript脚本和asp.net验证控件同时验证的代码
- JavaScript页面模板库handlebars的简单用法
- 框架页面高度自动刷新的Javascript脚本
- 简单的密码评级 js 脚本(简单的javascript判断密码安全性)