첨부 (표시/숨기기) 동적으로 그리고 클릭하면 아래의 필드 셋을 표시/숨기면
문제
스팬에 동적으로 첨부 (표시/숨기기)를 첨부하고 특정 텍스트를 클릭하면 아래 필드 세트에 표시/숨기기를 원합니다. 나는 쇼/숨기기 텍스트가 첨부 된 작업을 완수했다. 그러나 해당 텍스트를 클릭하면 문제가 발생합니다. 스팬 옆에있는 텍스트가 변경되는 것 외에는 아무 일도 일어나지 않습니다.
HTML :
<span>Store Dropdown</span>
<fieldset id="fieldset-store" class="showHide">
<legend>Choose by item:</legend>
<label for="prodtype">Type:</label>
<select name="prodtype" id="prodtype">
<option value="0" selected="selected">Choose type</option>
<option value="1"> Sample1</option>
<option value="2"> Sample2</option>
<option value="3"> Sample3</option>
<option value="4"> Sample4</option>
</select>
<label for="brandtype">of:</label>
<select name="brandtype" id="brandtype">
<option value="0" selected="selected">Choose brand</option>
<option value="1"> Brand1</option>
<option value="2"> Brand2</option>
<option value="3"> Brand3</option>
<option value="4"> Brand4</option>
</select>
<label for="prodprice">Price:</label> <input id="prodprice" name="prodprice" value="" type="text">
</fieldset>
JS 코드 :
$(document).ready(function(){
$(".showHide").prev().append(' <a href="#" class="showHideLink">Show</a>');
$(".showHide").hide();
$('a.showHideLink').click(function() {
if ($(this).html()=='Show')
$(this).html('Hide');
else
$(this).html('Show');
$(this).next().toggle('slow');
return false;
});
});
pls는 내가 어떤 변화를 해야하는지 제안합니다. 미리 감사드립니다
해결책
$(document).ready(function(){
$(".showHide").prev().append(' <a href="#" class="showHideLink">Show</a>');
$(".showHide").hide();
$('a.showHideLink').click(function() {
if ($(this).html()=='Show')
$(this).html('Hide');
else
$(this).html('Show');
$(".showHide").toggle('slow');
return false;
});
});
또는
$(document).ready(function(){
$(".showHide").prev().append(' <a href="#" class="showHideLink">Show</a>');
$(".showHide").hide();
$('a.showHideLink').click(function() {
if ($(this).html()=='Show')
$(this).html('Hide');
else
$(this).html('Show');
$(this).parent().next().toggle('slow');
return false;
});
});
제휴하지 않습니다 StackOverflow