use*_*293 0 javascript element click
我有一个简单的 html 文件上传表单,它是这样的:
<form action="upload_file.php" id="theForm" method="post" onsubmit="return validateForm()" enctype="multipart/form-data">
<label for="file">Files:</label>
<input type="file" name="file[]" id="file1"><button id="rem1" type="button">Remove File</button>
...
...
<input type="file" name="file[]" id="file99"><button id="rem99" type="button">Remove File</button>
<input type="submit" name="submit" value="Submit">
</form>
Run Code Online (Sandbox Code Playgroud)
输入是动态创建的。我需要知道被点击的按钮的 id。
如果您正在使用 jQuery,这应该会让您感到高兴:
// delegate click event to all button elements in #theForm;
// will also apply for buttons added in future
$('#theForm').on('click', 'button', function(e) {
alert(e.target.id);
});
Run Code Online (Sandbox Code Playgroud)
如果没有,请将其附加到每个按钮:
blablabla.onclick = function(event){
alert(event.currentTarget.id);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
38337 次 |
| 最近记录: |