更改标签的标题

时间:2013-07-24 00:03:39

标签: php javascript html xml

我试图从标签上改变标题,但它并没有改变。我已经调试过,变量不是null。这是我的代码:

html文件只加载xml和js文件....

这是我的xml文件:

<?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>
?>

在这里我的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));
}
          });
        });
      }

1 个答案:

答案 0 :(得分: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";
}

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