【问题标题】:Javascript Click the specific button in a web pageJavascript 单击网页中的特定按钮
【发布时间】:2018-12-04 20:08:37
【问题描述】:

这是我的工作示例页面https://graphicstogether.com/free-trial/

我正在使用 Wordpress 联系表格 7。问题是当我点击附件上的清除按钮时,它点击了发送按钮。如何单独控制每个按钮操作?

**

我也面临 JS 代码错误。我在页脚应用了这段 JS 代码。

**


HTML

<input type="file" name="file-860" size="40" class="wpcf7-form-control wpcf7-file" id="file1" accept=".jpg,.jpeg,.png,.gif,.pdf" aria-invalid="false">

<input type="file" name="file-860" size="40" class="wpcf7-form-control wpcf7-file" id="file2" accept=".jpg,.jpeg,.png,.gif,.pdf" aria-invalid="false">

Js

var f = document.querySelectorAll('input[type=file]'),
clearInput = function(){this.previousSibling.value = '';};
for(var i = 0; i < f.length; i++){
  button = document.createElement('button');
  button.textContent = 'clear';
  button.addEventListener('click', clearInput);
  f[i].parentNode.insertBefore(button, f[i].nextSibling);
}

【问题讨论】:

  • 您没有使用您键入的那个函数,而是尝试使用 jQuery 来清除文件?

标签: javascript jquery wordpress contact-form-7


【解决方案1】:

如果不发送表单,按钮必须为 type="button",否则为 type="submit"。

<button type="button">clear</button>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-11
    • 1970-01-01
    • 2023-01-24
    • 1970-01-01
    • 2012-10-09
    • 2016-10-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多