简体   繁体   English

如何让 Chrome 扩展 Popup.html 识别输入值?

[英]How to get Chrome Extension Popup.html to recognized the input value?

Why is my input value not being recognized through the Popup.html?为什么我的输入值无法通过 Popup.html 识别?

  <div id="color">
    <div id="isfruit">yes</div>
    <input type="text" id="enterfruit">
    <script type="text/javascript" src="peaches.js"></script>
    </div>

function basket() {
      var yespeach = $("#enterfruit").val();
      $("Peach is an orage color.").appendTo("#color");
}

document.getElementById('isfruit').addEventListener('click', basket);

I tried doing it through inline jQuery however it doesn't seem inline scripts are allowed.我尝试通过内联 jQuery 执行此操作,但似乎不允许使用内联脚本。

The only thing that doesn't look right on your code is the append;您的代码中唯一看起来不正确的是附加; For this kind of trouble you can see the console inside the chrome extension;对于这种麻烦你可以在chrome扩展里面看到控制台;

 function basket() { var yespeach = $("#enterfruit").val(); $("#color").append("<div> Peach is an orage color. value: "+yespeach+"</div>"); } document.getElementById('isfruit').addEventListener('click', basket);
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="color"> <div id="isfruit">yes</div> <input type="text" id="enterfruit"> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM