Javascript 单击网页中的特定按钮
Javascript Click the specific button in a web page
这是我的工作示例页面https://graphicstogether.com/free-trial/
我正在使用 Wordpress 联系表 7。问题是当我点击附件上的清除按钮时,它点击了发送按钮。如何单独控制每个按钮动作?
**
I'm also facing an error with JS code. I've applied this JS code at the footer.
**
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);
}
如果不发送表单,按钮必须是type="button",否则会是type="submit".
<button type="button">clear</button>
这是我的工作示例页面https://graphicstogether.com/free-trial/
我正在使用 Wordpress 联系表 7。问题是当我点击附件上的清除按钮时,它点击了发送按钮。如何单独控制每个按钮动作?
**
I'm also facing an error with JS code. I've applied this JS code at the footer.
**
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);
}
如果不发送表单,按钮必须是type="button",否则会是type="submit".
<button type="button">clear</button>