【问题标题】:Want to read input by Id instead of by name想要按 Id 而不是按名称读取输入
【发布时间】:2017-07-14 12:02:12
【问题描述】:

我希望 javascript 通过“id”实时读取我的输入字段 因为支付网关不允许在输入字段中添加名称

formSelectors: {
              numberInput: 'input[name="number"]',
              expiryInput: 'input[name="expiry"]',
              cvcInput: 'input[name="cvc"]',
              nameInput: 'input[name="name"]';
            }

【问题讨论】:

  • javascript live read my input field by "id"=>清除 javascript 或 jQuery?
  • 这听起来像是XY Problem

标签: javascript php payment-gateway 2checkout


【解决方案1】:

快速回答:

formSelectors: {
              numberInput: '#yourInputId'
            }

另外:

通过 id 获取元素的其他选项:

document.getElementById("yourInputId")

此外,每个具有 Id 的元素都已被 JavaScript 选择并存储在与 id 同名的变量中。例如

<div id="myid"></div>

您将在 javascript 中拥有变量 myid 并且可以使用它

console.log (myid.classList) // array of classes

【讨论】:

    【解决方案2】:

    我终于找到了解决办法,就是把名字改成id

    formSelectors: {
              numberInput: 'input[id="number"]',
              expiryInput: 'input[id="expiry"]',
              cvcInput: 'input[id="cvc"]',
              nameInput: 'input[id="name"]'
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-21
      相关资源
      最近更新 更多