【问题标题】:Is there a way to assign the user's input and/or selection into the message?有没有办法将用户的输入和/或选择分配到消息中?
【发布时间】:2021-11-16 12:54:00
【问题描述】:
<input type="radio" name="T" id="twenT">20
<input type="radio" name="T" id="sixT">60
<input id="uIn"></input>
<a href="sms://+15552345678;?&body=CHANGE%20THIS"></a>
<button onclick="function()">

如何使用户选择一个选项或输入文本,然后文本消息更改为选择/输入的文本。 首选纯 JavaScript。

【问题讨论】:

  • 您想要从 uIn 输入文本还是从单选按钮输入?
  • 现在,主要是单选按钮,但我希​​望两者都做。

标签: javascript sms href


【解决方案1】:

试试这个

我更改为 name="T" 以使它们成为有效的收音机

我还关闭了 A 以使其有效。如果您想点击链接并更改,那么我们可以删除按钮

const href = "sms://+15552345678;?&body="
const sms = document.getElementById("sms");
const uIn = document.getElementById("uIn");
document.getElementById("changeMsg").addEventListener("click",function(e) {
  const val = document.querySelector("input[name=T]:checked");
  if (val) {
    sms.href = href.split("body=")
      .join(`body=${encodeURIComponent(val.value)}&uIn=${encodeURIComponent(uIn.value)}`)
    console.log(sms.href)
  }  
  else {
    console.log("radio not checked")
  }
})
<input type="radio" name="T" value="twenT">20
<input type="radio" name="T" value="sixT">60
<input id="uIn" type="text" value="" />
<a id="sms" href="sms://+15552345678;?&body=CHANGE%20THIS">Call us</a>
<button id="changeMsg" type="button">Change</button>

【讨论】:

    猜你喜欢
    • 2019-09-08
    • 2023-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-18
    • 2020-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多