버튼이 생성 되었으면 어쨌든 다음과 같이 링크를 추가하거나 window.location 메소드를 사용할 수 있습니까 :`window.location = 'nextpage.html? foo = number'. 나는 현재이어떻게 동적으로 생성 된 버튼에 링크를 추가 할 수 있습니까?
var typeValue = location.search;
var typeStringValue= typeValue.replace("?type=","");
var containers = typeValue.replace("?type=multi","");
var containersValue = parseInt(containers);
var sampleLetter = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
function createButton(buttonName){
var buttonDivBlock = document.getElementById("sampleSets");
var buttonElement = document.createElement("input");
buttonElement.setAttribute("type","button");
buttonElement.setAttribute("name",buttonName);
buttonElement.setAttribute("value","Sample Set"+" "+buttonName);
buttonElement.setAttribute("id",buttonName);
buttonDivBlock.appendChild(buttonElement);
// document.getElementById(sampleLetter[i]).setAttribute('onclick',window.location='SampleInfo.html'+typeStringValue+bottonName);<!--add the button link -->
}
function setButtons(numberOfContainers){
for(i=0;i<numberOfContainers;i++){
createButton(sampleLetter[i]);
}
}
window.onload = function(){
setButtons(containersValue);
}
그러나 document.getElementById("'"+sampleLetter[i]+"'").setAttribute('onclick',window.location='SampleInfo.html'+typeStringValue+bottonName);<!--add the button link -->
반환 널 값을 가지고있다.
가능한 속는/관련 질문을 추가하지 마십시오, 루프 대신의
createButton
기능에서 설정하려는 경우 : http://stackoverflow.com/questions/789824/add-onclick-property-to-input-javascript, http://stackoverflow.com/questions/6909988/add-an-onclick-event-to-a-div,http://stackoverflow .com/questions/3316207/add-onclick-event-to-newly-added-element-in-javascript. . . "onclick"은 유효한 속성이 아니므로 샘플 코드가 시도하는 것입니다. – ernie글쎄 그게 아니라 성공을 시도했기 때문에 내가 뭘 찾고 있어요. : – Ch32k0
@ernie 다른 페이지에서도 여전히 사용했습니다. – Ch32k0