[英]How to pass table data from PHP to javascript to display it in the html form onclick of a submit button
[英]How to pass a PHP array as parameter from onClick HTML button to JavaScript?
当我按下 onClick 并调用 JavaScript function 时,我想传递一个数组。 我尝试将它作为参数传递,但它不起作用。 该数组是数据表中一行的数据,因此当我单击特定行的编辑按钮时,我只想获取该行的值并将其传递给 JavaScript。
<button type="button" id="button_edit" onclick="edit_customer_request()" value="<?php echo $user; ?>" name="edit_customer">Edit</button>
和 jQuery:
function edit_customer_request() {
var button_edit = document.getElementById("button_edit");
}
如果你想在 html 中分配 onclick ,你可以通过 arguments 到回调 ZC1C4145268E17A94D
function edit_customer_request(element,arr) { console.log($(element).prop('type')); console.log(arr); }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <button type="button" id="button_edit" onclick="edit_customer_request(this, [1,2,3])" value="<?php echo $user; ?>" name="edit_customer">Edit</button>
他们甚至在 w3schools 文档中有一个示例: https://www.w3schools.com/jsref/event_onclick.asp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.