2016-12-30 62 views
-4

我想增加輸入內的值一個 可以幫助我,因爲我是新來的JavaScript。 感謝你和你的幫助非常感謝增加文本輸入內的值 - javascript

下面

是代碼:

function myFunctions() { 
 
    var x = document.createElement("INPUT"); 
 
    x.setAttribute("type", "number"); 
 
    x.setAttribute("value", "1"); 
 
    var y = document.createElement("br"); 
 
    var z = document.createAttribute("readonly"); 
 
    document.body.appendChild(x); 
 
    document.body.appendChild(y); 
 
    x.setAttributeNode(z); 
 
}
<button onclick="myFunctions()">Try it</button>

回答

0

你可以試試下面的代碼:

var cnt=1; 
 
function myFunctions() { 
 
    var x = document.createElement("INPUT"); 
 
    x.setAttribute("type", "number"); 
 
    x.setAttribute("value", cnt); 
 
    var y = document.createElement("br"); 
 
    var z = document.createAttribute("readonly"); 
 
    document.body.appendChild(x); 
 
    document.body.appendChild(y); 
 
    x.setAttributeNode(z); 
 
    cnt++; 
 
}
<button onclick="myFunctions()">Try it</button>

+0

ohhhhh ..謝謝Bharatsing ...:d ..感激這麼多 –

+0

您的歡迎:) –

0

試試這個

var count = 0; 
 
function myFunctions() { 
 
    var x = document.createElement("INPUT"); 
 
    x.setAttribute("type", "number"); 
 
    x.setAttribute("value", count++); 
 
    var y = document.createElement("br"); 
 
    var z = document.createAttribute("readonly"); 
 
    document.body.appendChild(x); 
 
    document.body.appendChild(y); 
 
    x.setAttributeNode(z); 
 
}
<button onclick="myFunctions()">Try it</button>