如何使用javascript设置标签文本

时间:2014-02-10 05:59:51

标签: javascript

这是我的代码,我不知道为什么我不能将值存储到数据库

错误应该在这一行:

document.getElementById('divPrize').innerHTML = prizes[x]['name'];

代码:

// Now we can work out the prize won by seeing what prize segment startAngle and endAngle the relativeAngle is between.
for (x = 0; x < (prizes.length); x ++)
{
    if ((relativeAngle >= prizes[x]['startAngle']) && (relativeAngle <= prizes[x]['endAngle']))
    {
        // Do something with the knowlege. For this example the user is just alerted, but you could play a sound,
        // change the innerHTML of a div to indicate the prize etc - up to you.
        // store db 

        document.getElementById('divPrize').innerHTML = prizes[x]['name'];
        document.getElementById('<%=lblPrize.ClientID %>').attributes['Text'] = prize[x]['name'];

        alert("You won " + prizes[x]['name'] + "!\nClick 'Play Again' to have another go.");
        break;
    }
}

2 个答案:

答案 0 :(得分:1)

使用innerHTML属性

 document.getElementById('<%=lblPrize.ClientID %>').innerHTML = prize[x]['name'];

而不是

document.getElementById('<%=lblPrize.ClientID %>').attributes['Text'] = prize[x]['name'];

DEMO

答案 1 :(得分:0)

你可以试试这个......

document.getElementById('<%=lblPrize.ClientID %>').innerHTML = prize[x]['name'];
相关问题