将我的跨度值转换为输入值
我想通过表单提交一些(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);
};
亲切的问候, 莫里斯
I have some (javascript) values I want to submit via a form. One of these values I get using a span:
<span id="score_win" style="color:#ffbe5e;">0</span>
This wont submit in a form. So I though, let's convert the javascript output to get it into my input field. I thought this up for the input field:
<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 />
So far so good, only the value doesn't show now. This is because I haven't edited the javascript part yet. Problem is: how do I do that correctly so that this value can be used in my input field? Since my own attempts failed, I thought asking you guys.
The javascript part:
function foundMatchingBlocks(event, params) {
params.elements.remove();
//score += 100;
score += pointsAvailable;
$('#score').text(score);
$('#status2').html('+' + pointsAvailable);
pointsAvailable = 100;
$('#score_win').text(score);
};
Kind regards,
Maurice
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
.val()
函数而不是.text()
设置输入字段的值:Use the
.val()
function instead of.text()
to set the value of an input field: