1

I want to turn a number I get from a form into a string and combine it with another string, but I receive this:

windows.location='multiSet?type=multi'Number

instead I want to get this:

windows.location='multiSet?type=multiNumber'

Note that the difference is the position of the ' mark is before Number and I want it after it..

All i see in other post is how to put a string as a number not viceversa.

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();
}
4

1 回答 1

5

不要setAttribute用于定义事件处理程序。而且您不需要解析值,因为您想将其放回字符串中。

改变

document.getElementById("nextButton").setAttribute("onclick", multipleSetWindow+containerCuantityValue);

document.getElementById("nextButton").onclick = function(){
      window.location='multiSet.html?type=multi'+containerCuantity.value;
}
于 2013-07-12T14:26:34.320 回答