다음과 같은 형식이 있습니다.
<form action="http://example.co.uk/order" method="post" id="voucher" class="AVAST_PAM_nonloginform">
<fieldset>
<h4>Vouchers</h4>
<input type="text" class="discount_name form-control" id="discount_name" name="discount_name" value="">
<input type="hidden" name="submitDiscount">
<button type="submit" name="submitAddDiscount" class="button btn btn-default button-small"><span>OK</span></button>
</fieldset>
</form>
다음 스크립트를 사용하고 있습니다.
<script>
window.onload = function(){
document.getElementById(\"discount_name\").value = \"50681\";
}
</script>
입력을 채 웁니다. 그런 다음 다음을 사용합니다.
<script>
window.onload = function(){
document.forms['voucher'].submit();
}
</script>
제출을 활성화합니다.
그러나 두 번째 스크립트를 사용하면 "50681"이 텍스트 상자에 입력되는 것을 중지합니다 (대신 빈 입력을 제출 함).
원래 코드는 다음과 같습니다.
<script>
window.onload = function(){
document.getElementById(\"discount_name\").value = \"50681\";
document.forms['voucher'].submit();
}
</script>
(나는 그것이 타이밍 문제일지도 모른다고 생각하여 분할했습니다).
어떤 아이디어?
추신 백 슬래시의 이유는 내가 작동시킬 때까지 현재 PHP에서 실행되고 있기 때문입니다.
문제는 (\"discount_name\").value = \"50681\";
&document.forms['voucher'].submit();
두 경우 모두 숫자 \
로 타겟팅해야하는 & 양식을 피할 index
수 있습니다. 하나의 양식 만 존재한다고 가정하므로 0
index 전달
window.onload = function(){
document.getElementById("discount_name").value = "50681";
document.forms[0].submit();
}
참고 : 데모에서 액션 URL을 https
else로 변경했습니다 . jsfiddle에서 전화를 걸 수 없습니다. 귀하의 경우에는 여전히 http
코드를 유지할 수 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다