每次单击按钮时都将数字连接到 url?
Concatenate a number to url everytime I click on the button?
如何在每次单击按钮时将数字连接到字符串?
如果我记录 cConcate 变量,您会看到第一个值是正确的,但在随后的点击中 url 拒绝更新。
var tNumber = 1;
var sSting = "http://www.test.com/";
var cConcate = sSting + tNumber
$("button").click(function(){
tNumber++;
console.log(cConcate);
console.log(tNumber);
});
在点击处理程序中进行串联,而不是只进行一次:
var tNumber = 1;
var sString = "http://www.test.com/";
$("button").click(function(){
var cConcate = sString + tNumber++;
console.log(cConcate);
console.log(tNumber);
});
将您的 cConcate
放入 button click event
中,因为它应该会更新。
将您的代码更改为
var tNumber = 1;
var sSting = "http://www.test.com/";
var cConcate = sSting;
$("button").click(function(){
tNumber++;
cConcate= cConcate + tNumber;
console.log(cConcate);
console.log(tNumber);
});
或者如果您只想附加一个数字:
var tNumber = 1;
var sSting = "http://www.test.com/";
$("button").click(function(){
tNumber++;
var cConcate= sSting + tNumber;
console.log(cConcate);
console.log(tNumber);
});
你可以做到,
var tNumber = 1;
var sSting = "http://www.test.com/";
$("button").click(function(){
var cConcate = sSting + tNumber
console.log(cConcate);
console.log(tNumber);
tNumber++;
});
如何在每次单击按钮时将数字连接到字符串? 如果我记录 cConcate 变量,您会看到第一个值是正确的,但在随后的点击中 url 拒绝更新。
var tNumber = 1;
var sSting = "http://www.test.com/";
var cConcate = sSting + tNumber
$("button").click(function(){
tNumber++;
console.log(cConcate);
console.log(tNumber);
});
在点击处理程序中进行串联,而不是只进行一次:
var tNumber = 1;
var sString = "http://www.test.com/";
$("button").click(function(){
var cConcate = sString + tNumber++;
console.log(cConcate);
console.log(tNumber);
});
将您的 cConcate
放入 button click event
中,因为它应该会更新。
将您的代码更改为
var tNumber = 1;
var sSting = "http://www.test.com/";
var cConcate = sSting;
$("button").click(function(){
tNumber++;
cConcate= cConcate + tNumber;
console.log(cConcate);
console.log(tNumber);
});
或者如果您只想附加一个数字:
var tNumber = 1;
var sSting = "http://www.test.com/";
$("button").click(function(){
tNumber++;
var cConcate= sSting + tNumber;
console.log(cConcate);
console.log(tNumber);
});
你可以做到,
var tNumber = 1;
var sSting = "http://www.test.com/";
$("button").click(function(){
var cConcate = sSting + tNumber
console.log(cConcate);
console.log(tNumber);
tNumber++;
});