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

发布于 2024-12-21 22:14:40 字数 889 浏览 3 评论 0原文

我想通过表单提交一些(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人事已非 2024-12-28 22:14:40

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

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

Use the .val() function instead of .text() to set the value of an input field:

$('#score_win').val('100');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文