开发者

onCLick() problem

开发者 https://www.devze.com 2023-03-06 04:22 出处:网络
I have been reading to stay away from JavaScript for a lot of things, however I was messing around with it and it doesnt seem to work (unless I am blind and have missed something)

I have been reading to stay away from JavaScript for a lot of things, however I was messing around with it and it doesnt seem to work (unless I am blind and have missed something)

<SCRIPT LANGUAGE="text/javascript">
    function testResults() {
        System.out.println("Got into function");
}
</SCRIPT>

And this is my body:

<form action="" method="GET">
    <input type="button" value="Save" name="saveType" style="margin:10px;" onClick="testResults()"/>
</form>

From what I have seen of 开发者_Go百科javascipt this should be fine... Any suggestions?


Use console.log instead of system.out.println...

Javascript is not Java!


A few pointers:

  • it's type="text/javascript"
  • why capital letters?
  • System.out.println is Java

Stay away from JavaScript? Currently it's almost like the opposite, but as almost always it depends on what you have to do :)


to get it work use this instead:

Look here - jsfiddle

<form action="" method="GET">
    <input type="button" value="Save" name="saveType" style="margin:10px;" onClick="testResults()"/>
</form>

<script type="text/javascript">
    function testResults() {
        alert("Got into function");
}
</script>

it is type="text/javascript and not language="text/language" also in javascript you have to use alert().


Javascript doesn't have a standard output like that. You have a few options:

  • If you have a debugging console running, you can use console.log("log a message")
  • You can output debug information to a HTML element: document.getElementById("myelement").innerHTML = "message here";

There are loads more options - I'd suggest learning Javascript properly. It's not that much like Java.


  • Java => System.out.println or System.out.print
  • Javascript => console.log

:)

0

精彩评论

暂无评论...
验证码 换一张
取 消