如何将 PHP 数组作为参数从 onClick HTML 按钮传递到 JavaScript?

当我按下 onClick 并调用 JavaScript 函数时,我想传递一个数组。我尝试将其作为参数传递,但它不起作用。该数组是数据表中一行的数据,因此当我单击特定行的“编辑”按钮时,我只想获取该行的值并将其传递给 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");

}


慕的地10843
浏览 54回答 0
0回答

慕丝7291255

如果你想像你一样在 html 中分配 onclick,你可以将参数传递给回调函数: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>
打开App,查看更多内容
随时随地看视频慕课网APP