Qualtrics Table 条件格式

Qualtrics Table Conditional Formatting

在我的 Qualtrics 调查中,一个问题(描述性文本)是一个两列 table,其中填充了两个不同国家/地区的随机选择的嵌入数据(下面的 v2elsuffrage_ord 变量)。这两个变量都是数字 0-4。我想要做的是有条件地格式化这些单元格,因此无论哪个分数较大(score1 或 score2),该单元格都是绿色的。

这是我的 table 的示例:

<table class="UserTable">
    <colgroup>
        <col id="score1" />
        <col id="score2" />
    </colgroup>
    <tbody>
        <tr>
            <th>Country A</th>
            <th>Country B</th>
        </tr>
        <tr>
            <td>${e://Field/v2elsuffrage_ord}</td>
            <td>${e://Field/v2elsuffrage2_ord}</td>
        </tr>
    </tbody>
</table>

这在 Qualtrics 中甚至是可能的吗?我在 HTML 中找到了一个正常条件格式的示例,并尝试针对 Qualtrics 对其进行修改,但没有成功。这就是我作为 Javascript:

所做的
Qualtrics.SurveyEngine.addOnload(function()
{

    var score1 = $(this).text();
    var score2 = $(this).text();

    if (score1 > score2) {
        $(this).addClass('more1');
    }
    else if (score1 < score2) {
        $(this).addClass('more2');
    }
    else if (score1 = score2) {
        $(this).addClass('same');
    }
});

然后对于 CSS,我在 Look & Feel 的 Advanced 部分下添加了这段代码(现在随机选择颜色以查看它是否有效):

.more1 {
    background-color: #0f0;
}

.more2 {
    background-color: #0c0;
}

.same {
    background-color: #060;
}

我知道我肯定做错了,但我从来没有真正在 HTML/CSS 工作过(就像我说的,我什至不知道这是否可能)。任何想法或指导都会很棒,即使它只是一种解决方法。

你的 JavaScript:

中有一堆错误
  1. $(this) 错误
  2. text() 是一个 jQuery 函数,不是 prototypejs 或原生 JavaScript 函数
  3. score1 = score2 是无效比较
  4. addClass 不是一个有效的函数

此外,样式分配逻辑和 CSS 没有意义。你只需要一种风格。既然如此,那么给元素添加样式就简单多了。不需要单独的 CSS.

试试这个 JavaScript...

Qualtrics.SurveyEngine.addOnload(function()
{

var score1 = parseInt("${e://Field/v2elsuffrage_ord}");
var score2 = parseInt("${e://Field/v2elsuffrage2_ord}");

if (score1 > score2) {
    $('score1').style.backgroundColor = "#0f0";
}
else if (score1 < score2) {
    $('score2').style.backgroundColor = "#0f0";
}
});