首页 > 解决方案 > 未捕获的 ReferenceError:我的函数未在 HTMLInputElement.onclick 中定义

问题描述

当我在 Wordpress rawhtml 代码中插入此代码时,我在页面视图中出现此错误,您能帮我解决为什么会出现此错误吗?未捕获的 ReferenceError:我的函数未在 HTMLInputElement.onclick 中定义

这是代码片段:

function myfunction(id)
{
  if(id>4)
    {
      document.getElementById('msg2').style.display="block";
      document.getElementById('msg1').style.display="none";
      document.getElementById('url2').style.display="block";
      document.getElementById('url1').style.display="none";
    }
   else
    {
      document.getElementById('msg2').style.display="none";
      document.getElementById('msg1').style.display="block";
      document.getElementById('url1').style.display="block";
      document.getElementById('url2').style.display="none";
    }
}
<div class="cont">

<div class="stars">

  <form action="">
  <input class="star star-5" id="star-5" type="radio" name="star" onclick="return myfunction(5)"/>
  <label class="star star-5" for="star-5"></label>
  <input class="star star-4" id="star-4" type="radio" name="star" onclick="myfunction(4)"/>
  <label class="star star-4" for="star-4"></label>
  <input class="star star-3" id="star-3" type="radio" name="star" onclick="myfunction(3)"/>
  <label class="star star-3" for="star-3"></label>
  <input class="star star-2" id="star-2" type="radio" name="star" onclick="myfunction(2)"/>
  <label class="star star-2" for="star-2"></label>
  <input class="star star-1" id="star-1" type="radio" name="star" onclick="myfunction(1)"/>
  <label class="star star-1" for="star-1"></label>
</form>
</div>
  <br>
  <br>
  <h3 id="msg1" style="display:none;">Give us a feedback</h3>
  <h3 id="msg2" style="display:none;">Thank you! We'd be grateful if you could give us a short review</h3>
  <br>
  <a class="click_here" id="url1" href="#" style="display:none;">SUBMIT</a>
  <a class="click_here" id="url2" href="#" style="display:none;">SUBMIT</a>
</div>

标签: javascripthtml

解决方案


推荐阅读