내 사이트에 목록을 만들었습니다. 이 목록은 내 데이터베이스의 정보로 빌드되는 foreach 루프에 의해 생성됩니다. 각 항목은 다른 섹션이있는 컨테이너이므로 1, 2, 3 ... 등과 같은 목록이 아닙니다. 정보가있는 반복 섹션을 나열하고 있습니다. 각 섹션에는 하위 섹션이 있습니다. 일반 빌드는 다음과 같습니다.
<div>
<fieldset class="majorpoints" onclick="majorpointsexpand($(this).find('legend').innerHTML)">
<legend class="majorpointslegend">Expand</legend>
<div style="display:none" >
<ul>
<li></li>
<li></li>
</ul>
</div>
</div>
그래서 onclick = "majorpointsexpand ($ (this) .find ( 'legend'). innerHTML)"로 함수를 호출하려고합니다.
내가 조작하려는 div는 기본적으로 style = "display : none"이며 클릭시 표시되도록 javascript를 사용하고 싶습니다.
"$ (this) .find ( 'legend'). innerHTML"은이 경우 함수의 인수로 "Expand"를 전달하려고합니다.
다음은 자바 스크립트입니다.
function majorpointsexpand(expand)
{
if (expand == "Expand")
{
document.write.$(this).find('div').style = "display:inherit";
document.write.$(this).find('legend').innerHTML = "Collapse";
}
else
{
document.write.$(this).find('div').style = "display:none";
document.write.$(this).find('legend').innerHTML = "Expand";
}
}
나는 거의 100 % 내 문제가 구문이라고 확신하고 자바 스크립트가 어떻게 작동하는지에 대해 잘 알지 못한다.
jQuery가 문서에 다음과 같이 연결되어 있습니다.
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
에서 <head></head>섹션을 참조하십시오.