Javascript变量无法解析,显示为空白或null [英] Javascript variable not resolving, appears as a blank or null

查看:75
本文介绍了Javascript变量无法解析,显示为空白或null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在门户网站上的个人资料页面的YUI进度栏上工作,并且遇到麻烦,无法在AJAX调用后更新该栏.

这是view.jsp中的初始代码,该代码在页面加载时呈现进度条;

I am currently working on a YUI Progress Bar for a profile page on a portal, and have run into trouble getting the bar to update after an AJAX call.

This is the initial code in the view.jsp which renders the progress bar on page load;

var pb = new YAHOO.widget.ProgressBar({value:<c:out value="${percentage}" />,minValue:0,maxValue:100}).render(''divid'');


当用户在页面上编辑字段时,将进行AJAX调用以更新字段以及配置文件完成的百分比值.

这里还运行着一个功能,该功能应该更新进度条,但是不起作用.


When users edit a field on the page, there is an AJAX call to update the fields and also the percentage value of profile completion.

There is a function that is also run here, which should update the progress bar, but it isn''t working.

function() {
          items = this.get('responseData');
          var percentage = items[0].value;
          document.getElementById('percent').innerHTML = percentage + '%';
          var element = document.getElementById("divid");
          element.innerHTML = "";
          renderProgressBar(percentage, "divid");
       }

function renderProgressBar(percentage, id){
alert(percentage);

var pb = new YAHOO.widget.ProgressBar({value:10, minValue:0, maxValue:100}).render(id);
pb.set('value', percentage);

}



百分比值正在更新,因为我正在更新"percent" div的innerHTML,并且它正在正确更新.

我还会在renderProgressBar中显示一个警报,以确保在那里的值也正确.

但是,当涉及更新栏时,它根本不起作用,该值始终为null或为空.

有什么想法吗?

我还尝试在清除div标签后硬编码添加一个全新的进度条,这是呈现页面时的输出;



The percentage value is being updated, as I''m updating the innerHTML of the ''percent'' div, and it is correctly updating.

I also display an alert in the renderProgressBar to make sure the value is correct there also.

When it comes to updating the bar however, it just doesn''t work, the value is always null or empty.

Any ideas?

I also tried to hardcode adding an entirely new progress bar after clearing the div tag, here is the output when the page is rendered;

YAHOO.widget.ProgressBar({value:, minValue:0, maxValue:100}).render(''divid'');


如您所见,该值为空.


As you can see, the value is empty.

推荐答案

{percentage}"/>,minValue:0,maxValue:100}).render(''divid '');
{percentage}" />,minValue:0,maxValue:100}).render(''divid'');


当用户在页面上编辑字段时,将进行AJAX调用以更新字段以及配置文件完成的百分比值.

这里还运行着一个功能,该功能应该更新进度条,但是不起作用.


When users edit a field on the page, there is an AJAX call to update the fields and also the percentage value of profile completion.

There is a function that is also run here, which should update the progress bar, but it isn''t working.

function() {
          items = this.get('responseData');
          var percentage = items[0].value;
          document.getElementById('percent').innerHTML = percentage + '%';
          var element = document.getElementById("divid");
          element.innerHTML = "";
          renderProgressBar(percentage, "divid");
       }

function renderProgressBar(percentage, id){
alert(percentage);

var pb = new YAHOO.widget.ProgressBar({value:10, minValue:0, maxValue:100}).render(id);
pb.set('value', percentage);

}



百分比值正在更新,因为我正在更新"percent" div的innerHTML,并且它正在正确更新.

我还会在renderProgressBar中显示一个警报,以确保在那里的值也正确.

但是,当涉及更新栏时,它根本不起作用,该值始终为null或为空.

有什么想法吗?

我还尝试在清除div标签后硬编码添加一个全新的进度条,这是呈现页面时的输出;



The percentage value is being updated, as I''m updating the innerHTML of the ''percent'' div, and it is correctly updating.

I also display an alert in the renderProgressBar to make sure the value is correct there also.

When it comes to updating the bar however, it just doesn''t work, the value is always null or empty.

Any ideas?

I also tried to hardcode adding an entirely new progress bar after clearing the div tag, here is the output when the page is rendered;

YAHOO.widget.ProgressBar({value:, minValue:0, maxValue:100}).render(''divid'');


如您所见,该值为空.


As you can see, the value is empty.


尝试使用此

try to use this

document.getElementById(''<%=percent.ClientID%>'')



希望对您有所帮助!



hope it helps!


这篇关于Javascript变量无法解析,显示为空白或null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆