【问题标题】:CakePHP - Access table from inside a tabCakePHP - 从选项卡内访问表
【发布时间】:2017-09-08 22:07:44
【问题描述】:

我的页面有 4 个选项卡,每个选项卡内都有一个表格,我希望能够在某个选项卡内绘制表格的行。 现在我的代码绘制了所有表格的行,而不仅仅是一个表格。 我尝试了同一行代码的变体,但找不到正确的代码来访问一个表。

在每个选项卡中都有一个具有不同 ID 的表,我不知道如何根据需要分别访问每个表。我的代码的最后一部分有一个条件,并且在每个条件下,行都是不同的。它们应该是相同的,但我更改了它们以尝试访问表,但我找不到路。

也许您知道该行的正确代码。

谢谢。

我的代码页.ctp:

<div id="tab-1">
    <table id="tablesc">
    ...//samefor all
    </div>

<div id="tab-2">
    <table id="tablesd">
    ...//samefor all
    </div>
<div id="tab-3">
<table id="tablespr">
...//samefor all
</div>
<div id="tabs-4">
<table id="tablespr">
    <tr>
        <th width="5%">Codigo</th>
        <th colspan="2">Criterio</th>
    </tr>
    <?php echo $this->Form->create($file); ?>
    <?php $j=1; ?>
    <?php $indice = 1; ?>
    <?php foreach($xmlrecibidoSPR->entryresult as $entry):?>
    <tr>
        <td width="5%"><?php echo $entry->codigo; ?></td>
        <?php $etapa = '14';?>
        <td colspan="2"><?php echo $this->Form->input('criteriosSPR' . $j, array('options' => $opcionescriterios, 'label' => "", 'onchange' => 'cambio2(' . $indice . ', ' . $entry->resultnumber . ', ' . $etapa . ', ' . '\'' . $carpeta . '\'' . ', \'tablaspr\')')); ?></td>            
        </tr>       
    <?php ++$j; ?>
        <?php ++$indice; ?>
    <?php endforeach;?>
</table>
</div>

我的代码 custom.js:

function change(indicetabla, indicexml, etapa, carpeta, tabla){
    var xhttp = new XMLHttpRequest();
    xhttp.open("GET", "../webroot/files/pjs15/results.xml", false);
    xhttp.send();
    var xmlDoc = xhttp.responseXML;/* xml */
    var documento = xmlDoc.childNodes[0];
    var sufijo = "";
    if(etapa == 11 || etapa == 21){
        sufijo = "scp";
       } else if(etapa == 12 || etapa == 22){
        sufijo = "sd";
       } else if(etapa == 13 || etapa == 23){ 
        sufijo = "ieee";
       } else if(etapa == 14 || etapa == 24) {
        sufijo = "spr";
       } else{
        sufijo = "";
       }
    var table = document.getElementById(tabla);
        var t = document.getElementById("criterios" + sufijo +indicetabla);
    var selectedText = t.options[t.selectedIndex].text;

    $.ajax({
        url:'../webroot/js/ajax.php',
        method:'get',
        data:{name:indicexml, criterio:selectedText, etapa:etapa, carpeta:carpeta},
        success:function(data)
        {
            particula = selectedText.substr(0,2);
            if(particula=='CI')/* indicexml */
            {
                $("table").find('tr:eq(' + indicetabla + ')').css('background-color', '#98ff98');//mint
            }
            else if(particula=='CE')
            {
                document.getElementById("table").find('tr:eq(' + indicetabla + ')').css('background-color', '#f6b8b8');//powder pink
            }
            else
            {
                $("table" + sufijo).find('tr:eq(' + indicetabla + ')').css('background-color', '#fcf8e3');
            }
        },
        error:function(data)
        {
            alert("error");
        }
    });

【问题讨论】:

    标签: ajax forms cakephp tabs html-table


    【解决方案1】:

    jQuery id selectors 必须以 # 符号开头。

    您在这里将“表”与每个唯一后缀连接起来,但需要在选择器前面加上 #

    $("table" + sufijo).find('tr:eq(' + indicetabla + ')').css('background-color', '#fcf8e3');
    

    应该是

    $("#table" + sufijo).find('tr:eq(' + indicetabla + ')').css('background-color', '#fcf8e3');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多