반응형
jQuery는 정렬되지 않은 목록에서 모든 목록 항목을 제거합니다.
목록에서 모든 목록 요소를 삭제하는 jQuery 명령을 잊어버렸습니다.검색을 좀 해봤는데 예전에도 여러 번 했는데 명령을 잊어버렸을 뿐입니다.
$("ul").clear()
$("ul").empty()
둘 다 이 일을 해내지 못한 것 같습니다.또 어떤 명령입니까?
업데이트:
감사합니다 여러분, 제 선택기에 구문 오류가 좀 있나 봅니다.
$("ul").empty()잘 통합니다.다른 오류가 있습니까?
$('input').click(function() {
$('ul').empty()
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
<li>test</li>
<li>test</li>
</ul>
<input type="button" value="click me" />
http://jsfiddle.net/infernalbadger/D5ss8/
다른 사람들이 지적한 바와 같이,$('ul').empty() 다음과 같이 정상적으로 작동합니다.
$('ul li').remove();
JS Fiddle 데모.
작동해야 합니다.
$("ul").html('')
여러 개의 ul이 있고 특정 ul을 비우려면 ideg를 사용합니다.
<ul id="randomName">
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
<script>
$('#randomName').empty();
</script>
$('input').click(function() {
$('#randomName').empty()
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul id="randomName">
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
<ul>
<li>4</li>
<li>5</li>
</ul>
<input type="button" value="click me" />
$("u").empty()는 작동하고 아이들을 치워야 합니다.여기서 보실 수 있습니다.
var ul = document.getElementById("yourElementId");
while (ul.firstChild)
ul.removeChild(ul.firstChild);
반이나 id를 찾아보세요.아마도 이렇게 $("#resi_result").html("); 작동해야 합니다.
다음을 사용한 예:
<p>Remove LI's from list</p>
<ul>
<li>Test</li>
<li>Test</li>
<li>Test</li>
<li>Test</li>
<li>Test</li>
</ul>
<p>END</p>
setTimeout(function(){$('ul li').remove();},1000);
http://jsfiddle.net/userdude/ZAd2Y/
이것은 최소한의 코드로 나에게 효과가 있었습니다.
$(my_list).remove('li');
언급URL : https://stackoverflow.com/questions/7004059/jquery-remove-all-list-items-from-an-unordered-list
반응형
'programing' 카테고리의 다른 글
| MsgBox 예/Excel VBA 없음 (0) | 2023.09.11 |
|---|---|
| 오라클 타임스탬프 값을 현재에서 과거의 타임스탬프로 업데이트하는 방법 (0) | 2023.09.11 |
| 형제 값을 기반으로 한 노드와 XPath 일치 (0) | 2023.09.11 |
| 데이터베이스 세션과 관련하여 데이터베이스 잠금 및 웹 서버가 어떻게 협업합니까? (0) | 2023.09.11 |
| ASP에서 여러 인증 방식을 설정하려면 어떻게 해야 합니까?NET Core 2.0? (0) | 2023.09.11 |