2014-07-19 2 views
-1

초보자 용으로 불편을 끼쳐 드려 죄송합니다.하지만 답변을 찾기 위해 노력했지만 지금은 전문 지식이 필요하다고 생각합니다.jQuery 포커스() 및 자동 키프레스()

"li을 클릭하면 li에 쓰여진 텍스트가 검색 상자 (ID '# input #)에 표시되고 자동으로 요청이 시작됩니다."

내 스크립트가 제대로 작동하지만 요청/검색이 시작되지 않았습니다. 프로세스의 마지막 단계에서 차단되었습니다.

도움 주셔서 감사합니다.

HTML

<ul id="test"> 
    <li>Hello world</li> 
    <li>Hello world 2</li> 
</ul> 

자바 스크립트, JQuery와

<script type="text/javascript"> 
$(document).ready(function(){ 
    $("#test li").click(function(){ 
     varindex = $(this).text(); 
     $('#input').val("Text is in the search box!"+" "+varindex); 
    }); 
}); 
</script> 

<script type="text/javascript"> 
$(document).ready(function(){ 
    $("#test li").click(function(){ 
     $('#input').focus(); 
     $('#input').trigger(jQuery.Event('key', {which: 13})); 
    }); 
}); 
</script> 
+0

당신을인가 입력에서 형태? –

+0

전체 html을 게시 할 수 있습니까? –

+0

양식을 제출 하시겠습니까? 여기를 참조하십시오 : http://stackoverflow.com/questions/1200266/submit-a-form-using-jquery – JohnB

답변

0

이 작동 :

<head> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js"></script> 
<script> 
$(document).ready(function() { 
    $('#test li').click (function() { 
     $('#input').attr("value", $(this).text()); 
     $('#myform').submit(); 
    }); 
}); 
</script> 
</head> 
<body> 
<ul id="test"> 
<li> Hello world </li> 
<li> Hello world 2 </li> 
</ul> 
<form id="myform" action="xxx.yyy.zz" method="get"> 
<input id="input" name="myinput" type="text" /> 
</form> 
</body> 
+0

thansk를 사용하십시오. 나는 이것을 시도하지 않았지만 여전히 나는 양식을 사용하지 않고 검색 상자 만 사용한다고 생각한다. –