【问题标题】:Change Caption of Label更改标签的标题
【发布时间】:2013-07-24 00:03:38
【问题描述】:

我正在尝试动态更改标签中的标题,但它没有改变。我已经调试过了,变量不为空。这是我的代码:

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));
}
          });
        });
      }

【问题讨论】:

  • 那不是有效的 PHP。为什么 PHP 标记中包含 XML?
  • 我也不知道。我正在使用 html5 生成器

标签: php javascript html xml


【解决方案1】:
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";
}

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

【讨论】:

  • 那我该如何更改标题?
猜你喜欢
  • 2012-12-12
  • 1970-01-01
  • 2016-09-20
  • 2018-04-04
  • 1970-01-01
  • 1970-01-01
  • 2023-03-08
  • 2019-04-01
  • 2017-05-15
相关资源
最近更新 更多