这样的结构,
代码:HTML:
<tr name="trTagName" style="display: block; font-size: 13px; font-family: Courier New;">
<td name="tdTagName1">
原创ID:<a name="spArticleID" >239</a>
作者名:你好
</td>
<td name="tdTagName" style="font-size: 13px; font-family: Courier New;">
是否成功:<a name="spResult"></a>
</td>
</tr>
<tr name="trTagName" style="display: block; font-size: 13px; font-family: Courier New;">
<td name="tdTagName1">
原创ID:<a name="spArticleID" >249</a>
作者名:你好
</td>
<td name="tdTagName" style="font-size: 13px; font-family: Courier New;">
是否成功:<a name="spResult"></a>
</td>
</tr>
JAVASCRIPT:
<script type="text/javascript">
var resultArray = document.getElementsByName("spResult");
var artIDArray = document.getElementsByName("spArticleID");
var ajax=new AJAXRequest;
function Change()
{
for(var i = 0;i<artIDArray.length;i++)
{
ajax.get("/user/story/UpdateStoryHTML.ashx?aid="+artIDArray[i].innerHTML,
function OnComlete(obj){resultArray[i].innerHTML = obj.responseText;});
}
}
</script>
执行的结果绝对正确,就是在执行结果那里无法显示返回的值~
取也没有取到~
如果在for循环里面加个alert(i);结果就出来了~不知道怎么回事,请高手指教~
5 个解决方案
#1
function OnComlete(obj){resultArray[i].innerHTML = obj.responseText;});
放到change方法的外面 。
放到change方法的外面 。
#2
等待牛人来答.
#3
以后需再关注,现在先帮你顶一下
#4
算了,我自己说好了~
JS是单线程的~
所以要用一种好的设计来解决~
以下是萝卜提供的方法:
var ArtList = function(){//声明artlist类
this.list = []; //构造函数,创建art的数组
}
ArtList.prototype.addArt = function(art){
this.list.push(art);//声明插入数据方法
}
ArtList.prototype.doCall = function(){ //创建doCall方法,调用单个实例
for(var i = 0, l = this.list.length; i < l; i ++){
this.list[i].doCall();
}
}
var Art = function(artElm,resElm){ //创建art类的构造函数,2个属性:artElm,resElm
this.artElm = artElm;
this.resElm = resElm;
}
Art.prototype.ajaxHandler = function(obj){ //声明ajax返回附值方法
this.resElm.innerHTML = obj.responseText;
}
Art.prototype.doCall = function(){ //声明art类的doCall方法,3个私有属性,1个ajax.get方法。
var url = "/user/music/HTMLChange/SinMusHtmlChange.ashx?sid="+this.artElm.innerHTML;
var ajax = new AJAXRequest;
var _this = this;
ajax.get(url,function OnComplete(obj){_this.ajaxHandler.call(_this,obj);});
}
var artlist = new ArtList();//实例化ArtList
for(var i = 0,l = artIDArray.length; i < l; i ++){
artlist.addArt(new Art(artIDArray[i],resultArray[i]));//添加art实例
}
function Change()
{
artlist.doCall();//调用artlist的docall方法
}
JS是单线程的~
所以要用一种好的设计来解决~
以下是萝卜提供的方法:
var ArtList = function(){//声明artlist类
this.list = []; //构造函数,创建art的数组
}
ArtList.prototype.addArt = function(art){
this.list.push(art);//声明插入数据方法
}
ArtList.prototype.doCall = function(){ //创建doCall方法,调用单个实例
for(var i = 0, l = this.list.length; i < l; i ++){
this.list[i].doCall();
}
}
var Art = function(artElm,resElm){ //创建art类的构造函数,2个属性:artElm,resElm
this.artElm = artElm;
this.resElm = resElm;
}
Art.prototype.ajaxHandler = function(obj){ //声明ajax返回附值方法
this.resElm.innerHTML = obj.responseText;
}
Art.prototype.doCall = function(){ //声明art类的doCall方法,3个私有属性,1个ajax.get方法。
var url = "/user/music/HTMLChange/SinMusHtmlChange.ashx?sid="+this.artElm.innerHTML;
var ajax = new AJAXRequest;
var _this = this;
ajax.get(url,function OnComplete(obj){_this.ajaxHandler.call(_this,obj);});
}
var artlist = new ArtList();//实例化ArtList
for(var i = 0,l = artIDArray.length; i < l; i ++){
artlist.addArt(new Art(artIDArray[i],resultArray[i]));//添加art实例
}
function Change()
{
artlist.doCall();//调用artlist的docall方法
}
#5
求正解
#1
function OnComlete(obj){resultArray[i].innerHTML = obj.responseText;});
放到change方法的外面 。
放到change方法的外面 。
#2
等待牛人来答.
#3
以后需再关注,现在先帮你顶一下
#4
算了,我自己说好了~
JS是单线程的~
所以要用一种好的设计来解决~
以下是萝卜提供的方法:
var ArtList = function(){//声明artlist类
this.list = []; //构造函数,创建art的数组
}
ArtList.prototype.addArt = function(art){
this.list.push(art);//声明插入数据方法
}
ArtList.prototype.doCall = function(){ //创建doCall方法,调用单个实例
for(var i = 0, l = this.list.length; i < l; i ++){
this.list[i].doCall();
}
}
var Art = function(artElm,resElm){ //创建art类的构造函数,2个属性:artElm,resElm
this.artElm = artElm;
this.resElm = resElm;
}
Art.prototype.ajaxHandler = function(obj){ //声明ajax返回附值方法
this.resElm.innerHTML = obj.responseText;
}
Art.prototype.doCall = function(){ //声明art类的doCall方法,3个私有属性,1个ajax.get方法。
var url = "/user/music/HTMLChange/SinMusHtmlChange.ashx?sid="+this.artElm.innerHTML;
var ajax = new AJAXRequest;
var _this = this;
ajax.get(url,function OnComplete(obj){_this.ajaxHandler.call(_this,obj);});
}
var artlist = new ArtList();//实例化ArtList
for(var i = 0,l = artIDArray.length; i < l; i ++){
artlist.addArt(new Art(artIDArray[i],resultArray[i]));//添加art实例
}
function Change()
{
artlist.doCall();//调用artlist的docall方法
}
JS是单线程的~
所以要用一种好的设计来解决~
以下是萝卜提供的方法:
var ArtList = function(){//声明artlist类
this.list = []; //构造函数,创建art的数组
}
ArtList.prototype.addArt = function(art){
this.list.push(art);//声明插入数据方法
}
ArtList.prototype.doCall = function(){ //创建doCall方法,调用单个实例
for(var i = 0, l = this.list.length; i < l; i ++){
this.list[i].doCall();
}
}
var Art = function(artElm,resElm){ //创建art类的构造函数,2个属性:artElm,resElm
this.artElm = artElm;
this.resElm = resElm;
}
Art.prototype.ajaxHandler = function(obj){ //声明ajax返回附值方法
this.resElm.innerHTML = obj.responseText;
}
Art.prototype.doCall = function(){ //声明art类的doCall方法,3个私有属性,1个ajax.get方法。
var url = "/user/music/HTMLChange/SinMusHtmlChange.ashx?sid="+this.artElm.innerHTML;
var ajax = new AJAXRequest;
var _this = this;
ajax.get(url,function OnComplete(obj){_this.ajaxHandler.call(_this,obj);});
}
var artlist = new ArtList();//实例化ArtList
for(var i = 0,l = artIDArray.length; i < l; i ++){
artlist.addArt(new Art(artIDArray[i],resultArray[i]));//添加art实例
}
function Change()
{
artlist.doCall();//调用artlist的docall方法
}
#5
求正解