2013-03-19 45 views
0

何我可以創建一個JavaScript文本框,然後onclick,傳遞一個函數的參數?以下注釋掉線是問題創建窗體w/javascript並將變量傳遞到函數

var inputBox = document.createElement("input"); 

inputBox.staff = project.staff[j].name; 
inputBox.defaultValue = inputBox.staff; 
inputBox.onchange = changeHours; 

//inputBox.onclick = selectText(this); 

回答

3
inputBox.onclick=function(argument){ 
    selectText(this); 
}; 
+0

@ user2164017它爲你工作還是不工作? – 2013-03-20 12:27:34

0

只需設置onclick與你想要的功能。

var inputBox = document.createElement("input"); 

inputBox.staff = project.staff[j].name; 
inputBox.defaultValue = inputBox.staff; 
inputBox.onchange = changeHours; 
inputBox.onclick = function() { 
    selectText(this); 
};