[英]Text Fields in Chrome Extension?
Regbutton.js Regbutton.js
window.onload = timeout();
//document.getElementById('regButton').onClick = textfield();
function textfield () {
var x = document.createElement('INPUT'); // INPUT also works
x.setAttribute('type', 'text');
x.setAttribute('value', 'text');
}
function timeout(){
console.log("Loading");
var button = document.getElementById('regButton');
if(button != null){
console.log(button);
}else{
console.log("No button");
}
}
popup.html: popup.html:
<!DOCTYPE html>
<html>
<head>
<script src="regbutton.js"></script>
<script src="background.js"></script>
<--...-->
<button id="regButton" class="button" type="button">Regulations</button>
So I am trying to make a textfield on the button click, but it is not working, ideas? 因此,我试图在按钮单击上创建一个文本框,但是它不起作用,想法?
You need to add the created element to the document. 您需要将创建的元素添加到文档中。
function textfield() {
var x = document.createElement('INPUT'); // INPUT also works
x.setAttribute('type', 'text');
x.setAttribute('value', 'text');
document.body.appendChild(x);
}
Here is a fiddle with a working solution: 这是一个有效的解决方案:
https://jsfiddle.net/7gbq9yuo/ https://jsfiddle.net/7gbq9yuo/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.