您好,我如何在 HTML 中定义按钮点击功能,我试过类似的方法:
<input type="button" value="sth" onclick="
<script type="text/javascript">
function hello()(
window.print();
var z =document.GetElementById('ogog');
z.inneHTML="hello";
<script>
">
我必须在这里定义我的功能,因为我有代码可以生成一个站点,其中 header 我无法定义 javascript 函数,我想在单击按钮时使用一个函数。 这只是一个例子。 它应该是这样的?
最佳答案
您可以通过将脚本的字符串表示形式放入 onclick 处理程序来将脚本附加到按钮:
<input type="button" onclick="window.alert('Hi!')">
此代码将在单击按钮时执行。通常,script 标签用于定义可在 HTML 文档中的其他地方引用的脚本,而包含 JavaScript 代码的字符串用于文档正文中以实际执行该代码。
关于javascript - 在 javascript onbuttonclick 中定义函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4849683/