<!DOCTYPE html>
<html>
<body>
<button id="one">Try it</button>
<h1>JavaScript Functions</h1>
<p id="demo"></p>
<script>
var x=document.getElementById("one").addEventListener("click", onefunction);
function onefunction(){
//document.getElementById('demo').innerHTML=x;
return 1;
}
请检查上面提到的代码。
//**在此处输入代码**
我需要将 1 返回给 var x
最佳答案
这是您需要的:
HTML 部分:
<button id="one" onclick="onefunction()">Try it</button>
<p id="demo"></p>
JS 部分:
function onefunction() {
document.getElementById("demo").innerHTML = 1;
}
BUT I DO NOT RECOMMEND THIS WAY OF CODING
关于javascript - js点击按钮返回值的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39895019/