[英]I can't seem to pass a value to javascript function
我的代码是这样的
function show_file(itemid) { document.getElementById("itemid").innerHTML = "Testing"; }
<td id='$itemid' class='header-row'> MyText quote <button onclick='show_file($itemid)'> Button<i class='fa fa-angle-down'></i> </button> </td>
但是我收到此错误“无法设置 null 的属性 'innerHTML'”,所以 $itemid 的值似乎没有通过?
您应该传递实际函数的参数itemid
而不是字符串“itemid”
将其更改为:
function show_file(itemid) {
document.getElementById("itemid").innerHTML = "Testing";
}
到:
function show_file(itemid) {
document.getElementById(itemid).innerHTML = "Testing";
}
那是因为您在参数中为 getElementById 函数提供了一个字符串,而不是 itemid 变量。 尝试这个 :
function show_file(itemid) {
document.getElementById(itemid).innerHTML = "Testing";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.