如何解决Javascript-Chrome扩展中的数据传递问题
我创建了一个JavaScript函数,并将其保存在pop.js
个文件中。
这是我的popup.html
文件:
<html>
<head>
<title>News Verifier</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="popup.js"></script>
<body>
<div class="popupBox">
<img src="NV.png" alt="logo" width="100" height="100" class="image">
<h1>News Verifier</h1>
<form>
<p class="instruct">copy and paste the news below</p>
<textarea id="news" class="input" name="paragraph_text" cols="50" rows="10" placeholder="Paste here"></textarea>
<br><br><br>
<input type="submit" class="button" onlick="GetResult();" value="Verify">
<br><br>
</form>
</div>
</body>
</head>
</html>
popup.js
文件:
function GetResult()
{
var news = document.getElementById('news').value;
alert(news);
}
manifest.json
文件:
{
"manifest_version": 2,"name": "News Verifier","description": "This extension Prints the news entered in textBox","version": "1.0","background": {
"scripts": ["popup.js"],"persistent": false
},"icons": {
"128": "NV.png","48": "NV.png","16": "NV.png"
},"browser_action": {
"default_icon": "NV.png","default_popup": "popup.html"
},"permissions": [
"storage","notifications","contextMenus"
]
}
理想情况下,每当我单击“验证”时,应调用我的函数,并弹出一个对话框,其中应显示在文本框中输入的值,但每当单击“验证”时,都不会发生任何事情。我没有任何弹出框。
感谢您为我的问题提供了重要的时间。 谢谢你
解决方法
有2个错误:
-
onclick
的拼写为onlick
(尚不存在;)) - 输入
submit
类型的输入将提交相关表格,使用type='button'
function GetResult() {
var news = document.getElementById('news').value;
alert(news);
}
<html>
<head>
<title>News Verifier</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="popup.js"></script>
<body>
<div class="popupbox">
<img src="NV.png" alt="Logo" width="100" height="100" class="image">
<h1>News Verifier</h1>
<form>
<p class="instruct">Copy and paste the news below</p>
<textarea id="news" class="input" name="paragraph_text" cols="50" rows="10" placeholder="Paste here"></textarea>
<br><br><br>
<input class="button" type="button" onclick="GetResult();" value="Verify">
<br><br>
</form>
</div>
</body>
</head>
</html>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。