我有一个生成的按钮列表:
<?php
echo "<td> <button id='"{$cell}'" onclick='"ausfüllen($cell)'">{$cell}</button></td>"
?>
我想调用一个 JavaScript 函数:
<script>
function ausfüllen(text) {
document.getElementById("nv_durchwahl").value = "dw";
}
</script>
填写其他一些<td>
:
<td>
<input type="text" id="nv_durchwahl" name="nv_durchwahl" value="">
</td>
我就是这样尝试的。
按钮生成没有任何问题,但它不会填写表单。
有什么想法吗?
你忘了关闭函数括号
<script>
function ausfüllen(text) {
document.getElementById("nv_durchwahl").value = "dw";
}
</script>
并且没有 ID 为"nv_durchwahl"的元素。
尝试以这种方式连接...函数 Ausfüllen 接收一个字符串,检查如何转换为 HTML 代码...
<?php
echo "<td> <button id='".{$cell}."' onclick='ausfüllen(".'"'.{$cell}.'"'.")'>".{$cell}."</button></td>";
?>
当你说
填写表格。
意味着在 ID 为"nv_durchwahl"(应该是唯一的)的元素上放置值"DW"或"text"变量的内容?
<script>
function ausfüllen(text) {
//set the value of the element with the specific id to "dw"
//text is never used!
document.getElementById("nv_durchwahl").value = "dw";
}
</script>