2010-02-18 5 views
2

그래서, 여기에 거래가 있습니다. 이전 요소를 객체로 호출하기 위해 Element.previous를 사용하려고하는데 요소의 텍스트 만 가져옵니다. 이전 객체를 ID없이 무엇을 호출 할 수 있습니까? 예를 들어 클래스별로 이전 요소를 호출합니까?프로토 타입 : 이전 개체로?

답변

0

따라서 $ ('1') 부분적으로 알아 냈습니다. parentNode.previousSibling.firstChild는 이전 개체를 호출합니다.

개체가 삭제 된 경우 이전 개체를 호출하는 데 문제가 있습니다. 여기 스크립트가 있습니다.

<script src="lib/prototype.js" type="text/javascript"></script> 

<script type="text/javascript"> 
function printBr(element, index, array) { 
    document.write("<div class=\"row\">"); 
    document.write("<input type=\"text\" class=\"textfield\" onclick=\"$('a" + index + "').appear(); return false;\" id=\"" + index + "\" name=\"" + index + "\" value=\"" + element + "\"><br/>"); 
    if (index == 0) {} 
    else { 
    document.write("<div id=\"a" + index + "\" style=\"display:none;width:150px;height:25px;background-color:blue;\">"); 
    document.write("<a onmousedown=\"$('" + index + "').parentNode.previousSibling.firstChild.writeAttribute('value', $('" + index + "').parentNode.previousSibling.firstChild.value + $('" + index + "').value);$('" + index + "').remove();$('a" + index + "').hide(); return false;\"><< Move</a> | "); 
    document.write("<a onmousedown=\"$('a" + index + "').hide(); return false;\">X</a></div>"); 
    } 
    document.write("</div>"); 
} 

['hello, world','123','bye bye birdy'].forEach(printBr); 


</script> 
0

.previous하는 인수로 CSS 셀렉터 사용이 .previous. .previous ('span')와 같이. 또는 찾고있는 요소가 이전 요소가 아닐 수도 있습니다. 먼저()로 올라 가야 할 수도 있습니다.