·
前几天遇到一个难题,就是网上找到一段计数编号代码,想给它增加调节编号功能,一个网友虽然解决了此问题,但其改编后的代码,却又出现奇怪的现象,就是无法设置字体大小及颜色,此问题我还是第一次遇到。所以再求高手帮忙。另外,我曾想把那“加”“减”放在编号前面,想尽了办法,奇怪的是以前随心所欲办到的事,对这段代码却变成了无计可施。真不知是什么原因。大家试试看(把下边的代码复制到记事本上,后辍txt改为html,并用IE打开看看,然后试着改,看行不行?)。代码如下:
<HEAD>
<style type="text/css">body{margin-top: 0px; }</style>
</HEAD>
<TD ALIGN="right"><FONT style="FONT-SIZE: 28pt; FONT-FAMILY: 宋体,"><font color="red"><script type="text/javascript">
var caution = false;
function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "") ;
if (!caution || (name + "=" + escape(value)).length <= 4000)
document.cookie = curCookie
else
if (confirm("Cookie exceeds 4KB and will be cut!"))
document.cookie = curCookie
}
function getCookie(name) {
var prefix = name + "="
var cookieStartIndex = document.cookie.indexOf(prefix)
if (cookieStartIndex == -1)
return null
var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
if (cookieEndIndex == -1)
cookieEndIndex = document.cookie.length
return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}
function deleteCookie(name, path, domain) {
if (getCookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT"
}
}
function fixDate(date) {
var base = new Date(0)
var skew = base.getTime()
if (skew > 0)
date.setTime(date.getTime() - skew)
}
var now = new Date();
fixDate(now);
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
var totalLen = 6;
function changeNum(num){
var visits = getCookie("counter");
var str = ' ';
if (!visits || visits<=0){
visits = 1;
}else
{
visits =parseInt(visits)+num;
}
for(var i=0,len=visits.toString().length;i<totalLen-len;i++){
str += '0'; }
setCookie("counter", visits, now);
document.getElementById('counter').innerHTML = str+visits;
} window.onload = function(){
document.getElementById('add').onclick = function(){
changeNum(1);
}
document.getElementById('reduce').onclick = function(){
changeNum(-1);
}
changeNum(0);
}
</script>
</font></font></TD><table >
<tbody>
<tr>
<td>
<div id="counter"></div>
</td>
<td><input type="button" id="add" value="加"> <input type="button" id="reduce" value="减">
</td>
</tr>
</tbody>
</table>
前几天遇到一个难题,就是网上找到一段计数编号代码,想给它增加调节编号功能,一个网友虽然解决了此问题,但其改编后的代码,却又出现奇怪的现象,就是无法设置字体大小及颜色,此问题我还是第一次遇到。所以再求高手帮忙。另外,我曾想把那“加”“减”放在编号前面,想尽了办法,奇怪的是以前随心所欲办到的事,对这段代码却变成了无计可施。真不知是什么原因。大家试试看(把下边的代码复制到记事本上,后辍txt改为html,并用IE打开看看,然后试着改,看行不行?)。代码如下:
<HEAD>
<style type="text/css">body{margin-top: 0px; }</style>
</HEAD>
<TD ALIGN="right"><FONT style="FONT-SIZE: 28pt; FONT-FAMILY: 宋体,"><font color="red"><script type="text/javascript">
var caution = false;
function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "") ;
if (!caution || (name + "=" + escape(value)).length <= 4000)
document.cookie = curCookie
else
if (confirm("Cookie exceeds 4KB and will be cut!"))
document.cookie = curCookie
}
function getCookie(name) {
var prefix = name + "="
var cookieStartIndex = document.cookie.indexOf(prefix)
if (cookieStartIndex == -1)
return null
var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
if (cookieEndIndex == -1)
cookieEndIndex = document.cookie.length
return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}
function deleteCookie(name, path, domain) {
if (getCookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT"
}
}
function fixDate(date) {
var base = new Date(0)
var skew = base.getTime()
if (skew > 0)
date.setTime(date.getTime() - skew)
}
var now = new Date();
fixDate(now);
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
var totalLen = 6;
function changeNum(num){
var visits = getCookie("counter");
var str = ' ';
if (!visits || visits<=0){
visits = 1;
}else
{
visits =parseInt(visits)+num;
}
for(var i=0,len=visits.toString().length;i<totalLen-len;i++){
str += '0'; }
setCookie("counter", visits, now);
document.getElementById('counter').innerHTML = str+visits;
} window.onload = function(){
document.getElementById('add').onclick = function(){
changeNum(1);
}
document.getElementById('reduce').onclick = function(){
changeNum(-1);
}
changeNum(0);
}
</script>
</font></font></TD><table >
<tbody>
<tr>
<td>
<div id="counter"></div>
</td>
<td><input type="button" id="add" value="加"> <input type="button" id="reduce" value="减">
</td>
</tr>
</tbody>
</table>
<html xmlns="http://www.w3.org/1999/xhtml">
<style type="text/css">
body{
margin-top: 0px;
}
#counter{
color:#F00;
font-size:36px;
}
</style>
</HEAD>
<TD ALIGN="right"><FONT style="FONT-SIZE: 28pt; FONT-FAMILY: 宋体,"><font color="red"><script type="text/javascript">
var caution = false;
function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "") ;
if (!caution || (name + "=" + escape(value)).length <= 4000)
document.cookie = curCookie
else
if (confirm("Cookie exceeds 4KB and will be cut!"))
document.cookie = curCookie
}
function getCookie(name) {
var prefix = name + "="
var cookieStartIndex = document.cookie.indexOf(prefix)
if (cookieStartIndex == -1)
return null
var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
if (cookieEndIndex == -1)
cookieEndIndex = document.cookie.length
return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}
function deleteCookie(name, path, domain) {
if (getCookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT"
}
}
function fixDate(date) {
var base = new Date(0)
var skew = base.getTime()
if (skew > 0)
date.setTime(date.getTime() - skew)
}
var now = new Date();
fixDate(now);
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
var totalLen = 6;
function changeNum(num){
var visits = getCookie("counter");
var str = ' ';
if (!visits || visits<=0){
visits = 1;
}else
{
visits =parseInt(visits)+num;
}
for(var i=0,len=visits.toString().length;i<totalLen-len;i++){
str += '0'; }
setCookie("counter", visits, now);
document.getElementById('counter').innerHTML = str+visits;
} window.onload = function(){
document.getElementById('add').onclick = function(){
changeNum(1);
}
document.getElementById('reduce').onclick = function(){
changeNum(-1);
}
changeNum(0);
}
</script>
</font></font></TD>
<body>
<table >
<tbody>
<tr>
<td><input type="button" id="add" value="加"> <input type="button" id="reduce" value="减">
</td>
<td>
<div id="counter"></div>
</td></tr>
</tbody>
</table>
</body>
</html>
不明白你的意思