[英]jQuery clone function is not working in chrome
$(function() { var m_row = 0; $("body").on("click", "#m_add", function() { console.log("click lagche"); var result = "0"; var row; row = '<tr id="row_' + m_row + '">'; var clone = $("#m_input_file").clone(); clone.attr('id', ""); clone.attr('name', "m_input_file" + m_row); row += '<td id="file_' + m_row + '"></td>'; row += '<td><input type="hidden" name="m_sl[]" value="' + m_row + '"></td>'; row += '</tr>'; $("#workmanship_check table tbody").prepend(row); console.log(clone); $("#file_" + m_row).html(clone); m_row++; }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table id="workmanship_check" > <thead> <tr> <th> <input type="file" id="m_input_file"> </th> <th><a href="#" id="m_add">Add</a></th> </tr> </thead> <tbody> </tbody> </table>
它可以在Mozilla firefox浏览器中运行,但不能在Chrome中运行。
有什么办法可以工作吗?
如果没有,请提出如何动态地添加带有值的输入文件?
我如何动态地添加输入文件的价值
您不能,可靠地。 浏览器在输入文件时要非常小心,因为它们有潜在的安全漏洞。 您可以在保留文件值的同时移动文件元素,但不能在浏览器中可靠地保留文件的值,而又不能在所有浏览器中可靠地克隆它,其原因与无法创建具有默认值的元素相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.