0
사용자가 div의 가시성을 토글 할 수 있도록 두 개의 별도 jQuery 함수가 있습니다. 기본적으로 div는 닫힌 상태가됩니다. 쿼리 문자열에 전달 된 ID를 기반으로 특정 div를 열 것 입니다이 페이지에 대한 링크를 설정하는 방법을 찾으려고 노력하고있어. 내 jQuery를은 다음과 같습니다쿼리 문자열을 통해 이벤트를 트리거하는 jQuery
jQuery(document).ready(function(){
//make first div always open
jQuery(".toggle_container:not(:first)").hide();
jQuery(".toggle_container:first").show();
jQuery("h6.trigger:first").addClass("active");
jQuery("h6.trigger").click(function(){
jQuery(this).toggleClass("active");
jQuery(this).next(".toggle_container").slideToggle(300);
});
//The second function
jQuery(function(){
jQuery(".toggleIt").click(function(){
jQuery(this).next(".hiddenText").slideToggle("fast");
jQuery(this).html(function(i,html) {
if (html.indexOf('+') != -1){
html = html.replace('+','-');
} else {
html = html.replace('-','+');
}
return html;
})
});
});
HTML
<h6 class="trigger" id='uniqueID"></h6>
<div class="toggle_container">
TEST
</div>
//and the second toggled container
<p class="toggleThis tips" id="AnotherID">+</p>
<div class="hiddenText2">
Another TEST
</div>
나는 URL의 쿼리 문자열에 ID를 추가하고 같은 ID로 숨겨진 DIV를 열고있는 것입니다. 나는 지금까지 이와 같은 구조를 가지고있다. ...
var category = getParameterByName('cat');
var id = getParameterByName('id');
if(id)
{
}
else if(category)
{
}
else
{
//moving this in here
jQuery(".toggle_container:not(:first)").hide();
jQuery(".toggle_container:first").show();
jQuery("h6.trigger:first").addClass("active");
}
나는이 부분에 갇혀있다. 어떤 팁?
정말 쿼리 문자열을 통해 전달해야합니다. – Peachy
예, 동의합니다 ... 쿼리 문자열을 통해 전달합니다. 페이지 생성 언어는이를 HTML 입력 요소에 값으로 포함시킵니다. jQuery가이를 선택하고 그에 따라 작동합니다. – Fosco
아마도 내가 오해했을 것입니다. 나는 이것을 프론트 엔드에 유지할 필요가있다. 클릭 이벤트를 발생시키는 방법이 있거나 해시 + var를 사용하여이를 트리거하는 방법이 있다고 확신합니다. 그냥 내려 놓을 수는 없습니다. 그래도 고마워! – Peachy