简体   繁体   English

处理 HTML 中的多个复选框

[英]Processing multiple checkbox in HTML

I am not an expert with HTML and JavaScript.我不是 HTML 和 JavaScript 的专家。 But here is what I am trying to do.但这是我正在尝试做的。

I have creating an HTML/jQuery/JS/CSS script.我创建了一个 HTML/jQuery/JS/CSS 脚本。

The HTML file lists the number of files in the tabular form ( The number is not fixed) and I have checkboxes for each of the file. HTML 文件以表格形式列出了文件数(数字不固定),并且每个文件都有复选框。

The user can select one or more files to be deleted and click on "Submit" button.用户可以选择一个或多个要删除的文件,然后单击“提交”按钮。

Here is what I have tried :这是我尝试过的:

  • List all the files in the tabular column列出表格列中的所有文件
  • Include checkbox <td><input type="checkbox" id="deletefile" /></td>包含复选框<td><input type="checkbox" id="deletefile" /></td>
  • Submit button提交按钮
  • Prompt the user to confirm all the files提示用户确认所有文件
  • I have written the code to delete the file in Python (I need to call the right URL to delete a single file)我已经在 Python 中编写了删除文件的代码(我需要调用正确的 URL 来删除单个文件)

I am not sure how to process all the checkbox entries in HTML/JavaScript.我不确定如何处理 HTML/JavaScript 中的所有复选框条目。

In jQuery you can get the input checkbox checked list by using the following code:在 jQuery 中,您可以使用以下代码获取输入复选框选中列表:

$('input:checked').each(function(i){
val[i] = $(this).val();
}

Here val[i] contains the array ie, checked checkbox list so pass this array data to server-side code to delete from server.Hope this helps you :-)这里val[i]包含数组,即选中的复选框列表,因此将此数组数据传递给服务器端代码以从服务器中删除。希望这对您有所帮助:-)

EDIT:编辑:

Once check the live example below:一旦检查下面的实时示例:

http://jsfiddle.net/rN2gm/ http://jsfiddle.net/rN2gm/

Select checkbox and click button after that again unselect and click.选择复选框并单击按钮,然后再次取消选择并单击。

<td><input type="checkbox" name="deletefile[0]" /></td>
<td><input type="checkbox" name="deletefile[1]" /></td>

Use an array and you can identify each checkbox.使用数组,您可以识别每个复选框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM