div (또는 양식)를 검색하기 위해 텍스트 범위를 어떻게 얻을 수 있습니까? 이미 사용할 수있는 스크립트 또는 div 텍스트를 검색하는 jquery 함수가 있습니까?div에서 검색 할 자바 스크립트 함수 구현, 검색을 위해 텍스트 범위 가져 오기
는이 코드와 사업부에 양식을 추가합니다
$('#'+card_id).append('<form id="frm_search" name="frm_search" class="editableToolbar frm_search_links"> <input type="text" placeholder="Type a string..." name="linkcard_search_string" class="txt_form"> <a href="#" title="Search" class="ico_search btn_form" onClick="search_links(\''+card_id+'\', this.form); "></a> <a href="#" title="Close" class="ico_delete btn_form" onClick="close_search(\''+card_id+'\', this.form); "></a> </form>');
내가 해당 사업부에서 문자열을 찾습니다 검색 기능을 가지고 싶습니다. 나는 이처럼 텍스트 범위를 지정한다.
txt = window.document.body.getelementbyid(card_id).createTextRange();
검색 기능은 내가 인터넷에서 발견 한 내가 전체 페이지 대신 사업부를 검색 업데이트하는 것을 시도하고있다. 페이지에 여러 div가 있으며 각 검색에 특정 검색이 필요합니다. 그 기능을 search_links(card_id);
에서 호출합니다.
function search_links (card_id, form) {
var search_str = document.frm_search.linkcard_search_string.value;
/* alert('search_links '+search_str); */
return search_linkcard(search_str, card_id);
}
var IE4 = (document.all);
var n = 0;
function search_linkcard(str, card_id) {
alert (card_id + ' ' + str);
var txt, i, found;
if (str == "")
return false;
// Find next occurance of the given string on the page, wrap around to the
// start of the page if necessary.
if (IE4) {
txt = window.document.body.getelementbyid(card_id).createTextRange();
// Find the nth match from the top of the page.
for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
txt.moveStart("character", 1);
txt.moveEnd("textedit");
}
// If found, mark it and scroll it into view.
if (found) {
txt.moveStart("character", -1);
txt.findText(str);
txt.select();
txt.scrollIntoView();
n++;
}
// Otherwise, start over at the top of the page and find first match.
else {
if (n > 0) {
n = 0;
search_linkcard(str, card_id);
}
// Not found anywhere, give message.
else
alert("Not found.");
}
}
return false;
}
궁금한 점은 질문 : 입력란의 텍스트 범위를 어떻게 지정합니까? 내가 갖고있는 구문이 맞습니까? 이미 원하는대로, 즉 특정 div의 내용을 검색하는 스크립트가 있습니까?
http://api.jquery.com/contains-selector/ – NimChimpsky
@NimChimpsky의 클릭으로 사업부의 내용을 다시 추가 문자열을 찾아') ('.contains을 알 수있는 방법이 있나요 단추. 이렇게하면 완전한 검색 기능을 만들 수 있습니다. – user823527
도 있습니다. http://www.w3schools.com/jsref/jsref_search.asp – NimChimpsky