将我的跨度值转换为输入值

时间:2011-12-18 15:14:30

标签: javascript jquery forms input html

我想通过表单提交一些(javascript)值。我使用span来获得这些值之一:

<span id="score_win" style="color:#ffbe5e;">0</span>

这不会以表格形式提交。所以我想,让我们将javascript输出转换为我的输入字段。我想到了输入字段:

<input type="text" id="score_win" name="Score" value="0" style="text-align: left; background:transparent; border-style: none; color:#ffbe5e; margin: 0px; font: 14px Arial; width:40px;" readonly />

到目前为止这么好,现在只显示价值。这是因为我还没有编辑过javascript部分。问题是:我该如何正确地做到这一点,以便可以在我的输入字段中使用此值?由于我自己的尝试失败了,我想问你们。

javascript部分:

function foundMatchingBlocks(event, params) {
      params.elements.remove();
      //score += 100;
      score += pointsAvailable;
      $('#score').text(score);
      $('#status2').html('+' + pointsAvailable);
      pointsAvailable = 100;
      $('#score_win').text(score);
};

亲切的问候, 莫里斯

1 个答案:

答案 0 :(得分:2)

使用.val()功能代替.text()设置输入字段的值:

$('#score_win').val('100');
相关问题