0

I'm trying to change the caption from my label dinamically, but it doesn't change. I have already debugged and the variable isn't null. Here is my code:

The html file only load the xml and js files....

Here is my xml file:

<?php
<object class="MPage1" name="MPage1" baseclass="MPage">
<property name="DesignConfigName">iPhone - Vertical (320x480)</property>
<property name="DesignConfigWidth">320</property>
<property name="DesignConfigHeight">480</property>
<property name="UseBackground">1</property>
  <property name="Animations">a:0:{}</property>
  <property name="Background"></property>
  <property name="Caption">MPage1</property>
  <property name="Font">
  <property name="Family">Helvetica, Arial, sans-serif</property>
  <property name="Size">16px</property>
  </property>
  <property name="Height">480</property>
  <property name="HiddenFields">a:0:{}</property>
  <property name="Name">MPage1</property>
  <property name="Width">320</property>
  <property name="jsOnAjaxCallComplete">MPage1AjaxCallComplete</property>
  <property name="jsOnLoad">MPage1Load</property>
  <object class="MButton" name="MButton1" >
    <property name="Animations">a:0:{}</property>
    <property name="Caption">Teste</property>
    <property name="Height">43</property>
    <property name="Left">99</property>
    <property name="Name">MButton1</property>
    <property name="Top">57</property>
    <property name="Width">150</property>
    <property name="jsOnClick">MButton1Click</property>
  </object>
  <object class="MLabel" name="MLabel1" >
    <property name="Animations">a:0:{}</property>
    <property name="Caption">dsadasdsa</property>
    <property name="Font">
    <property name="Family">Helvetica, Arial, sans-serif</property>
    <property name="Size">16px</property>
    </property>
    <property name="Height">115</property>
    <property name="Left">77</property>
    <property name="Name">MLabel1</property>
    <property name="Top">175</property>
    <property name="Width">195</property>
  </object>
</object>
?>

and here my javascript:

 function showRecords() {
        results.text = '';
        db.transaction(function(tx) {
          tx.executeSql(selectAllStatement, [], function(tx, result) {
                             dataset = result.rows;
            for (var i = 0, item = null; i < dataset.length; i++) {
              item = dataset.item(i);
              var texto= item['nome'] + ' , ' + item['estoque'];
              var areaDeTexto = document.getElementsByName('MLabel1');
              areaDeTexto.Caption = texto;
            //  alert(areaDeTexto.value));
}
          });
        });
      }
4

1 回答 1

0
var areaDeTexto = document.getElementsByName('MLabel1');
areaDeTexto.Caption = texto;

areaDeTexto 将是一个集合,您不能为集合设置标题。您需要遍历集合以单独更改标题。(可能还有其他错误..)

添加假设一切正常,您可以使用以下方法循环遍历元素(与当前循环分开):

var areaDeTexto = document.getElementsByName('MLabel1');
for (var j = 0; j < areaDeTexto.length; j++) {
    areaDeTexto.Caption = "some caption";
}

但我在这里做了很多假设;特别是,您可以通过这种方式更改标题。

于 2013-07-24T00:16:41.543 回答