2012-09-18 4 views
0

나는 다음과 같은 시작 HTML이 : 여기 제안에서둘 이상의 요소에 대해 jQuery 선택기를 결합 할 수 있습니까?

<div id="modal" ><div class="modal-window"> 
<ul class="action-tabs right"> 
<li><a href="#" title="Close window"> 
<img src="/Content/images/icons/fugue/cross-circle.png" width="16" height="16"></a></li> 
</ul> 
<div class="block-content"><h1>xx</h1> 
<div class="modal-content> 
... 
</div> 
</div> 
</div> 

을 나는 다음과 같은 jQuery 코드 한 : 실제로 지금까지 하나 하나있다 (

$modal 
    .find('.modal-content') 
    .wrap("<form id='modal-form'>") 
$modal 
    .find('#modal-form') 
    .find("button") 
    .filter(function() { 
     return $(this).text().toLowerCase().indexOf('submit') != -1; 
    }) 
    .prop('type', 'submit'); 

내가해야 할 것은이를 선두를 찾을 수를) 클래스의. .modal-content. 그럼 <form id="xxx"></form>"에 이것을 감쌀 필요가 있습니다.

다음으로 양식을 살펴보고 텍스트 제출을 포함한 모든 버튼을 찾고 유형을 "제출"유형으로 변경하십시오.

나는 위의 코드가 그렇게 할 것이라고 생각하지만 좀 더 단순하게 만들 수 있을지 궁금해하고 있습니다. 또한 .wrap을 수행하는 몇 가지 방법에 대한 제안 사항이 있습니다. 이러한 제안 이었다 :

$('.modal-content').wrap('<form id="xxx" />'); 
$(".modal-content").wrap('<form id="xx"></form>'); 
$('.modal-content').wrapAll('<form />'); 

는 모두 사용이 올바른 것입니까?

는 나는 훨씬 간단하지만, 어쩌면 보는 것이 을 할 수 있다고 생각하지 않습니다
+0

시작 HTML은 무엇입니까? HTML 조작이 끝나면 무엇을할까요? –

+0

시작 HTML로 질문을 업데이트했습니다. 내가해야 할 일은 내가 갖고있는 jQuery로 덮여 있다고 생각한다. 두 jQuery를 결합 할 수 있는지 알고 싶습니다. 감사합니다 –

+0

당신은 아마 할 수 있습니다; 그러나 우리가 최종 결과를 볼 수 있다면 더 쉽고/더 안정적이며/더 효율적이거나 대안적인 jQuery 접근법을 제공 할 수 있습니다. 도움을 주실 분 * ** * ** **. –

답변

0

당신은 정의 할 수 있습니다 소문자를 구분하지 않는이 같은 :contains : 다음

$.extend($.expr[':'], { 
    "contains-ci": function(elem, i, match) { 
    return jQuery.fn.text.apply(elem).toLowerCase().indexOf(match[3].toLowerCase()) > -1; 
    } 
}); 

그리고 :

$modal 
.find('.modal-content') 
.wrap('<form id="modal-form">') 
.find('button:contains-ci("submit")') 
.prop('type', 'submit'); 

이 솔루션은 버튼을 모두 함께이 있다고 가정하고 그냥 주위에 양식을 포장.

0

:

$modal 
    .find('.modal-content:first') 
    .wrap('<form id="modal-form" />') 
    .find("button") 
    .filter(function() { 
     return $(this).text().toLowerCase().indexOf('submit') != -1; 
    }) 
    .prop('type', 'submit'); 

나는 그래서 당신은하지 않고 그 안에있는 버튼을 찾을 수 있어야합니다 wrap()은 원래로 돌아 요소 .modal-content 생각 form 요소에서 다른 find()을 수행하십시오.

관련 문제