형제 자매를 중심으로 어떤 경우에도 사용자가 레이블을 클릭 할 때마다 해당 입력에 초점을 맞추는 방법을 알아 내려고 노력하고 있습니다. 지금이 순간이 바로 그 곳입니다. 누구나 의견이나 제안이 있으면 크게 감사하겠습니다.강제 입력
Q
강제 입력
0
나는 현재 워드 프레스를 통해 문의 양식 플러그인 등 출력 된 HTML 함께 일하고 있어요 및 다음과 같이 JS 보이는
A
답변
1
는 <label>
에 for
속성은 id
하지name
을 찾습니다. 당신이 정말로 자바 스크립트/JQuery와 함께이 작업을 수행하지하려면 $(this).next().children().focus();
<div class="form--field form--field__firstname">
<label for="firstname" class="form--field__label">First Name</label>
<span>
<input type="text" id="firstname" name="firstname">
</span>
</div>
없이 작동
$('.form--field__label').click(function() {
$(this).next().children().focus();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="form--field form--field__firstname">
<label class="form--field__label">First Name</label>
<span>
<input type="text">
</span>
</div>
<div class="form--field form--field__secondname">
<!-- using a span instead of label as an example !-->
<span class="form--field__label">Second Name</span>
<span>
<input type="text">
</span>
</div>
0
세트 입력 I d = "firstname"왜냐하면 레이블 클릭에 집중하기를 원하기 때문입니다. 이것은 html의 내장 기능입니다. 당신은 아직도 당신이
$('.form--field label').click(function() {
//It will look next sibling which is span and then find input in it and then focus it
//so it doesn't focus on other children elements
$(this).next('span').find('input').focus();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="form--field form--field__firstname">
<label class="form--field__label">First Name</label>
<span>
<input type="text" name="firstname">
</span>
<br>
<label class="form--field__label">Last Name</label>
<span>
<input type="text" name="lastname">
</span>
</div>
여러 입력
<input type="text" id="firstname" name="firstname">
자세한 내용이
<form action="/action_page.php">
<label for="male">Male</label>
<input type="radio" name="gender" id="male" value="male"><br>
<label for="female">Female</label>
<input type="radio" name="gender" id="female" value="female"><br>
<label for="other">Other</label>
<input type="radio" name="gender" id="other" value="other"><br><br>
<input type="submit" value="Submit">
</form>
처럼 사용할 수 있습니다
관련 문제
- 1. 문자로만 입력 패턴 강제 입력
- 2. 강제 전환 입력 방법
- 3. div를 왼쪽으로 강제 입력
- 4. keydown 이후 강제 키 입력
- 5. 입력 값의 녹아웃 강제 업데이트
- 6. C의 sscanf를() 강제 번호 입력
- 7. 선택 후 사용자 입력 강제 수행
- 8. 기본 텍스트로 시작하는 텍스트 영역 입력 강제
- 9. Qt 현지 시간대를 UTC로 강제 입력
- 10. 빈 인터페이스가있는 "일반"코드로 강제 입력
- 11. Google 시트의 줄 끝 문자 강제 입력
- 12. 모바일 웹 사이트에 숫자 입력 강제 실행
- 13. AIR Android 강제 숫자 텍스트 입력
- 14. jQuery를 사용하여 입력에 입력 이벤트 강제 적용
- 15. 강제 입력 양식이 vue.js의 대문자에서 백엔드로 입력됩니다.
- 16. 강제 값 강제 강제 적용
- 17. 강제
- 18. 강제
- 19. 강제
- 20. 강제
- 21. 강제/강제 변환 평가는 여기
- 22. 울퉁불퉁 한 배열의 요소를 지정된 범위 내로 강제 입력
- 23. Tcl/Tk 입력 필드에서 대문자 입력을 강제 실행합니다.
- 24. listview의 검색 필터 막대에서 숫자 입력 키패드를 강제 실행하는 방법?
- 25. 돼지 : 입력 줄/행당 하나의 매퍼 강제 적용
- 26. AngularJS 강제 제출 일부 숨겨진 된 입력 값을 보내지 마십시오
- 27. Divx를 입력 할 때 레이블을 읽도록 강제 화면 판독기
- 28. 강제 입장 URL
- 29. TinyMCE에서 강제 텍스트 색
- 30. Solr : 특정 노드에서 강제 노드 시작 강제
아! 고마워요. 어떤 이유에서인지 나는 항상 라벨에 'for'가 'name'과 관련이 있다고 가정했다. 매력처럼 일했습니다. – thelgloriouspast