按html按钮时如何执行JavaScript?[关闭]

问题描述 投票:-4回答:1

我已经提供了一些截图。如果需要的话,我也可以把整个网站的文件夹发过来。

enter image description here

enter image description here

javascript html function button
1个回答
1
投票

你是想在jQuery对象上使用DOM方法。你不能把它们混在一起。

$(".work").click(function() {
    $("#main_page, #work_page, #contacts_page").hide();
    $("#work_page").show();
    $("#main-body").css("background-image", "url(resources/fons_mani.jpg)");
});

0
投票

下面的代码是一个简单的例子。这个例子来自W3Schools。那里有很多关于javascript函数的例子。我建议你去看看。下面的例子可以在这个URL上执行。https:/www.w3schools.comjsreFtryit.asp?filename=tryjsref_onclick

<!DOCTYPE html>
<html>
<body>

<h1>The onclick Event</h1>

<p>The onclick event is used to trigger a function when an element is clicked on.</p>

<p>Click the button to trigger a function that will output "Hello World" in a p element with id="demo".</p>

<button onclick="myFunction()">Click me</button>

<p id="demo"></p>

<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "Hello World";
}
</script>

</body>
</html>
© www.soinside.com 2019 - 2024. All rights reserved.