2011-12-18 55 views
1

我想通过表单提交一些(javascript)值。其中一个值使用跨度:将我的跨度值转换为输入值

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

亲切的问候, 莫里斯

回答

2

使用.val()函数,而不是.text()设置输入字段的值:

$('#score_win').val('100'); 
+0

AAaaaahhhh这么简单! !谢谢,那就是诀窍! – Maurice 2011-12-18 15:37:47