我想将一个从表单中获得的数字转换为字符串并将其与另一个字符串组合,但我收到了:
windows.location='multiSet?type=multi'Number
Run Code Online (Sandbox Code Playgroud)
相反,我想得到这个:
windows.location='multiSet?type=multiNumber'
Run Code Online (Sandbox Code Playgroud)
请注意,差异是'标记在之前的位置,Number我希望它在之后...
我在其他帖子中看到的是如何将字符串作为数字而不是反之亦然.
var singleMultiContainer = document.getElementById("singleMultiContainer");
var singleMultiValue = singleMultiContainer.value;
var nextButton = document.getElementById("nextButton");
var multipleSetWindow = "window.location='multiSet.html?type=multi'";
var singleSetWindow = "window.location='SampleInfo.html?type=single'";
var containerCuantity = document.getElementById("containerCuantity");
function setContainers(){
singleMultiValue = singleMultiContainer.value;
containerCuantityValue = parseInt(containerCuantity.value);
if (singleMultiValue == "multi"){
//alert("Multi");
document.getElementById("nextButton").setAttribute("onclick", multipleSetWindow+containerCuantityValue);
} else if (singleMultiValue == "single") {
document.getElementById("nextButton").setAttribute("onclick", singleSetWindow);
}
}
singleMultiContainer.onchange = function(){
setContainers();
}
Run Code Online (Sandbox Code Playgroud)
不要setAttribute用于定义事件处理程序.并且您不需要解析该值,因为您希望将其放回字符串中.
更改
document.getElementById("nextButton").setAttribute("onclick", multipleSetWindow+containerCuantityValue);
Run Code Online (Sandbox Code Playgroud)
至
document.getElementById("nextButton").onclick = function(){
window.location='multiSet.html?type=multi'+containerCuantity.value;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
116 次 |
| 最近记录: |