我想在HTML中创建一个按钮,单击该按钮会显示javascript代码(提示)。我该怎么做呢?谢谢!
答案 0 :(得分:0)
它会起作用!
<强> HTML:强>
<input id="button" type="button" value="Klick me"/>
<强>使用Javascript:强>
document.getElementById("button").onclick = function() {
confirm("Great to see you," + " " + prompt("What's Your Name"));
};
答案 1 :(得分:0)
<input name="button1" type="button" value="click me" onclick="clickme()"/>
<p id="value"></p>
<script type="javascript">
function clickme()
{
var s = prompt("write a number");
if(s!=null)
document.getElementById("value").innerHTML= s;
}
</script>
将提示的值放在段落
中答案 2 :(得分:0)
请仔细阅读
<form name="my_form" id="form_id" method="post" action="my_page_url">
<!-- rest part of your form fields go here -->
<!-- this is the submit button -->
<input type="submit" name="my_button" value="but_value" onclick="myfunction()"/>
</form>
您可以像这样提交此表单。请注意,还有很多其他方法可以做到这一点。
<script type="text/javascript">
function myfunction()
{
document.getElementById('form_id').submit();
}
</script>
请仔细阅读一些教程。有很多教程。进行谷歌搜索。祝你好运