2013-01-31 2 views
0

캡션과 함께 여러 개의 이미지를 추가하는 양식을 만들고 싶습니다. 내가 PHP와 MySQL을 사람으로 해요. 그래서 addmore를 클릭하면 새로운 필드를 얻을 수 있다면 나머지 PHP mysql 부분을 할 수 있습니다. var x를 설정하여 새로운 열을 만들어 새로운 찾아보기 버튼과 캡션 텍스트 필드를 제공 할 수 있습니다. 그것은 가장 아름다운 방법하지만 간단하고 빠른 방법은 테이블을 제공하는 아마 아니에요자바 스크립트를 사용하여 html 요소를 삭제하십시오.

+0

도움이 될 것입니다. http://jsfiddle.net/JV8eU/ – DON

+0

감사합니다. – ashish

답변

0

<script type="text/javascript"> 
<!-- 
function addMore() { 
if (document.getElementById && document.createElement) { 
    var x = ; 
    document.getElementById('inserthere').appendChild(x); 
} 
else alert('Your browser doesn\'t support the Level 1 DOM'); 
} 

function delMore() { 
if (document.getElementById && document.createElement) { 
    var node = document.getElementById('inserthere') 
    node.removeChild(node.childNodes[0]); 
} 
else alert('Your browser doesn\'t support the Level 1 DOM'); 
} 
// --> 
</script> 

</head> 

<body> 
<table> 
<tr><td>Select Image<input type="file" name="img[]" id="img" /></td><td>Add caption 
<input type="text" name="img_cap[]" id="img_cap" /></td> 
</tr> 
<span id="inserthere"></span> 
</table> 

<a href="javascript:addMore()" class="page">add More</a><br /> 
<a href="javascript:delMore()" class="page">remove</a> 

</body> 

누군가가 내가 배우고 인터넷을 탐구하고 시도하려고 시도 하겠어 응답까지 ..... id 당신이 생각 자세한 내용을 원하는대로

var x = document.createElement('tr'); // create a new row ready to add 
x.innerHTML = '<td>Select Image<input type="file" name="img[]" id="img" /></td><td>Add caption <input type="text" name="img_cap[]" id="img_cap" /></td>'; // fill it with your code 
document.getElementById('imgtable').appendChild(x) // add the new row to the table 

것은 appendin의 방법으로 document.createDocumentFragment() 같은 방법을 찾아주십시오 : 속성 (예를 들어, 'imgtable', 예를 들어), 그리고 당신의 addMore() 기능에서 다음을 수행 g 개별적으로 선언 된 요소를 실제로 DOM에 추가하기 전에 객체에 추가합니다. 내가 사용했던 innerHTML 메서드는 더 빠를 수 있지만 깔끔한 것은 아니며 문서 조각을 선언하는 것보다 디버깅하기가 더 어려울 수 있습니다.

희망이 도움이됩니다.

+0

고맙습니다 ....... 그것은 잘 작동하고 있습니다. 또한 그것을 이해했습니다. 이제는 크로스 버튼을 클릭하면 행을 제거 할 수 있습니다. ... – ashish

+0

제거를 위해 모두 제거하고 있습니다. 적어도 1 행 남았습니다. 또는 어떻게 든 자식 노드의 수를 계산하고 설정할 수 있습니다. 조건? – ashish

관련 문제