如何使用HTML制作的按钮启用我的javascript代码?

时间:2014-01-06 00:41:28

标签: javascript html function button

我想在HTML中创建一个按钮,单击该按钮会显示javascript代码(提示)。我该怎么做呢?谢谢!

3 个答案:

答案 0 :(得分:0)

Chek this out

它会起作用!

<强> 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>

请仔细阅读一些教程。有很多教程。进行谷歌搜索。祝你好运