This is a very basic question for web development!

Asked 1 years ago, Updated 1 years ago, 63 views

Leave the local server open I ran a simple front-end code It works well on Idle, but it doesn't work properly on Chrome.

There's a simple icon in the composition of the screen, and you click on it In other words, it is about calling a function that I made randomly in the JavaScript file at the time of onclick This function just gets and uses ajex to get Jason-type data from the server.

Actually, when I took it on the console, it wasn't a problem with the content of the function, and when I clicked it, the function I defined itself didn't run, so why is that?

In Iple, the function works well and receives data well, but in Chrome, the defined function itself is not executed. If you look at it on the console, JavaScript itself is good at singing.

I'd appreciate it if you could help me!

web google-chrome front-end

2022-09-22 21:12

1 Answers

Rather than writing onclick attributes, why don't you grab dom in JavaScript and give it an eventlistener? For example,

<div onclick="myFunc()"> Kanada Ramabasa</div>

I think it would be better to make html with id and bind event by catching DOM in JavaScript than to do the above code.

as shown below
<div="my-div"> Kanada Ramabasa</div>
<script>
  var myDiv = document.querySelector('#my-div');
  myDiv.addEventListener('click', myFunc);
</script>

If this doesn't solve the problem, you might have used the <a></a> tag. For example;

<a href="#" onclick="myFunc()"></a>

If you use the code as shown above, href may cause onclick to run incorrectly for each browser.
Why don't you take out href and try it?

I think it's fun to develop JavaScript if you encounter a lot of the above problems. If you study a little more, you will be able to make something cooler. Because we can make servers and robots with JavaScript.

There are many ways to learn JavaScript.

The company site I work for is giving away free ways to become a JavaScript full stack developer. A full-stack developer is a developer who can use JavaScript to create a website, as well as a server, a robot, etc.

If you go to http://www.svcoding.com and write down your email, please check it out.


2022-09-22 21:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.