2010-01-18 4 views
0

웹 응용 프로그램 개발을 위해 Struts2를 사용하고 있습니다. 나는 내가 봤지도 솔루션을 찾을 수 couldnt이 특정 문제가 있습니다.struts2 파일 입력 태그를 지울 수 있습니까?

각각에 대해 하이퍼 링크 또는 버튼이있는 3 개의 태그가 있습니다. 이전에 선택되어있는 경우 파일 경로를 지우는 데 사용해야합니다. 온라인에서 발견 된 해결책은 양식을 재설정하는 것이었지만 모든 태그가 동일한 양식에 있어야하므로 모든 s : 파일 태그가 지워집니다.

클릭 할 때 단일 파일 입력을 지울 수있는 방법이 있습니까 ??

답변

1

우리가 사용한 것과 비슷한 한 가지 해결책은 입력 요소를 제거하고 그 위치에 동일한 이름으로 새로운 입력 요소를 만드는 것입니다.

편집 : 여기에 내가 함께 던진 예가 있습니다.

<script type="text/javascript"> 
    function clearFoo() { 
     var inp = document.getElementById("foo"); 
     var parent = inp.parentNode; 

     // Create the new input element. 
     // Copy over any attributes you need. 
     var newInp = document.createElement("input"); 
     newInp.type = "file"; 
     newInp.name = inp.name; 

     // Replace the old node with the new node. 
     parent.insertBefore(newInp, inp); 
     parent.removeChild(inp); 

     // The new node is the new "foo". 
     newInp.id = "foo"; 
    } 
</script> 

<s:file id="foo" name="foo"/> 

<button onclick="clearFoo();">Click</button> 
+0

스트럿츠 태그로 가능합니까 ?? 어떤 생각? :-) – Richie

+0

's : file'에서 변경해야하는 것은'id' 속성을 추가하는 것입니다. 예제를 추가했습니다. – ZoogieZork

관련 문제