工作如何激活功能事件点击(或其他功能)时从浏览器激活



前,我会写信询问当我单击浏览器的特定区域时,onclick事件没有激活的问题是什么。 检查指南后,我发现问题结束了,我的简单测试的呈现也是微不足道的,我已经知道在浏览器文本区域中激活特定功能的机制。现在工作了...我想添加我的问题的更多详细信息...从模板 html 激活我的函数以标记<script></script>的机制是什么?

    <h3> Check is palindrome</h3>
        <input type="text" id="input1"  >
        <input type="text" id="input2">
        <br><br>
        <input type="button" id="reload" onclick="myFunction()" value="ricarica">
        <body > 
               <p onclick="check()" id="output" style="line-height: 1000px"> TEST</p>
        </body>
    //WHAT IS THE MECHANISM IN THIS POINT FOR ACTIVATE check()?
 <script>    
    function check() {
        var x = document.getElementById("input1").value;
        var y = document.getElementById("input2").value;
        if(x===y){
            document.getElementById("output").innerHTML=" E' PALINDROMA "
        }else  document.getElementById("output").innerHTML=" NON E' PALINDROMA "";
    }
    function myFunction() {
        location.reload(true);
    }

    </script>
    </html>

关于你的代码的一切都是错误的。喜欢。。。从字面上看,一切。下面是一个建议的替代方案:

var out = document.getElementById('output');
document.getElementById('input').oninput = function() {
  if( this.value.split('').reverse().join('') === this.value) {
    out.innerHTML = "The input is a palindrome!";
  }
  else {
    out.innerHTML = "The input is not a palindrome...";
  }
};
<input type="text" id="input" />
<p id="output">Type something...</p>

我了解,将您的check()函数移动到input字段

<input type="text" id="text1" onclick="check()">

并从body中删除

<body>

最新更新