[英]I can't seem to pass a value to javascript function
My code is like so我的代码是这样的
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>
But I get this error "Cannot set property 'innerHTML' of null" so it seems the value of $itemid is not getting passed?但是我收到此错误“无法设置 null 的属性 'innerHTML'”,所以 $itemid 的值似乎没有通过?
You should pass the actual function's parameter itemid
not the string "itemid"您应该传递实际函数的参数
itemid
而不是字符串“itemid”
Change it from:将其更改为:
function show_file(itemid) {
document.getElementById("itemid").innerHTML = "Testing";
}
To:到:
function show_file(itemid) {
document.getElementById(itemid).innerHTML = "Testing";
}
That is because you gived a string in parameter to your getElementById function and not the itemid variable.那是因为您在参数中为 getElementById 函数提供了一个字符串,而不是 itemid 变量。 Try this :
尝试这个 :
function show_file(itemid) {
document.getElementById(itemid).innerHTML = "Testing";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.