关于删除最后一个字符串的问题。求帮助 jquery js 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!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><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script type="text/javascript">var a=[];function change(x){ document.getElementById('test').innerHTML+=x; a.push(x);}function change2(){ var div=document.getElementById('test'); var t=div.innerHTML; var p=a.pop(); if(p){ var end=t.lastIndexOf(p); t=t.substring(0,end); div.innerHTML=t; }}</script></head><body><div id="test"></div><input type="button" value="我的" onclick="change('我的')"><input type="button" value="名字" onclick="change('名字')"><input type="button" value="是zyx" onclick="change('是zyx')"><input type="button" value="删除上一步" onclick="change2()"></body></html>类似这样试试 <!DOCTYPE html><html><head><meta charset="UTF-8"><title>Insert title here</title></head><body><div id='show'></div><button id='b1'>my</button><button id='b2'>name</button><button id='b3'>is zjx</button><button id='clear'>clear one</button><script type="text/javascript">function $(id){ return document.getElementById(id);}function init(){ var sets=[]; function b1fn(){ if(!b1fn.clicked){ sets.push('my'); //b1fn.clicked=true; $('show').innerHTML=sets.join(''); } } function b2fn(){ if(!b2fn.clicked){ sets.push(' name'); //b2fn.clicked=true; $('show').innerHTML=sets.join(''); } } function b3fn(){ if(!b3fn.clicked){ sets.push(' is zjx'); //b3fn.clicked=true; $('show').innerHTML=sets.join(''); } } function clear(){ sets.pop(); $('show').innerHTML=sets.join(''); } $('b1').addEventListener('click',b1fn); $('b2').addEventListener('click',b2fn); $('b3').addEventListener('click',b3fn); $('clear').addEventListener('click',clear);}init();</script></body></html> 按楼上朋友的思路可以解决你的问题.可以修改成这样:function change2(){ a.pop(); document.getElementById('test').innerHTML=a.join('');} 咨询一个Jquery绘图插件 HighCharts 使用的问题? 2个JS有冲突 求解决办法 急寻正则表达式开发测试工具!!! 函数调用 图片显示特效 js如何判断字符串是否包含某些特定的中文字符 请高手指点,急急............我在线等! JS向JSP传递中文参数出现了乱码,请大家帮帮我呀 很头疼的图片上传问题 js拼接字符串 求高手帮忙看一段JS的写法 一段小代码,ie6下无法运行
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
var a=[];
function change(x){
document.getElementById('test').innerHTML+=x;
a.push(x);
}
function change2(){
var div=document.getElementById('test');
var t=div.innerHTML;
var p=a.pop();
if(p){
var end=t.lastIndexOf(p);
t=t.substring(0,end);
div.innerHTML=t;
}
}
</script>
</head><body>
<div id="test"></div>
<input type="button" value="我的" onclick="change('我的')">
<input type="button" value="名字" onclick="change('名字')">
<input type="button" value="是zyx" onclick="change('是zyx')">
<input type="button" value="删除上一步" onclick="change2()">
</body>
</html>
类似这样试试
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body><div id='show'></div><button id='b1'>my</button>
<button id='b2'>name</button>
<button id='b3'>is zjx</button>
<button id='clear'>clear one</button>
<script type="text/javascript">
function $(id){
return document.getElementById(id);
}
function init(){
var sets=[];
function b1fn(){
if(!b1fn.clicked){
sets.push('my');
//b1fn.clicked=true;
$('show').innerHTML=sets.join('');
}
}
function b2fn(){
if(!b2fn.clicked){
sets.push(' name');
//b2fn.clicked=true;
$('show').innerHTML=sets.join('');
}
}
function b3fn(){
if(!b3fn.clicked){
sets.push(' is zjx');
//b3fn.clicked=true;
$('show').innerHTML=sets.join('');
}
}
function clear(){
sets.pop();
$('show').innerHTML=sets.join('');
}
$('b1').addEventListener('click',b1fn);
$('b2').addEventListener('click',b2fn);
$('b3').addEventListener('click',b3fn);
$('clear').addEventListener('click',clear);
}
init();</script></body>
</html>
function change2(){
a.pop();
document.getElementById('test').innerHTML=a.join('');
}