2017-02-18 18 views
0

Regbutton.jsChrome拡張機能のテキストフィールド?

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:

<!DOCTYPE html> 
<html> 
    <head> 
     <script src="regbutton.js"></script> 
     <script src="background.js"></script> 
    <--...--> 

    <button id="regButton" class="button" type="button">Regulations</button> 

だから私は、ボタンのクリックでテキストフィールドを作成しようとしていますが、それは、アイデアを動作していませんか?

+0

? –

答えて

0

作成した要素を文書に追加する必要があります。ここで

function textfield() { 
    var x = document.createElement('INPUT'); // INPUT also works 
    x.setAttribute('type', 'text'); 
    x.setAttribute('value', 'text'); 
    document.body.appendChild(x); 
} 

は、作業溶液とフィドルです:テキストフィールドを追加しようとしている

https://jsfiddle.net/7gbq9yuo/

関連する問題