type="file"
이미지를 업로드 하는 데 사용하는 HTML 입력 태그를 비활성화하려고합니다 . 예 또는 아니오를 표시하기 위해 라디오 옵션을 사용하고 있습니다. 사용자가 아니오를 클릭하면 입력 텍스트 상자가 비활성화됩니다. 이것은 내가 사용한 코드이지만 내가 뭘 잘못했는지 모르겠습니다.
$('#inputattrib').change(function() {
$('#images').prop('disabled', false);
});
$('#inputattribf').change(function() {
$('#images').prop('disabled', true);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="form-group">
<p> Indicate Payment Method:</p>
<input id="inptrue" type="radio" name="pmethod" value="Yes">Yes
<input id="inpfalse" type="radio" name="pmethod" value="No">No
</div>
<div class="form-group">
<label for="file">Upload your Payment Evidence: <i>for Bank Deposit only</i></label>
<input id="images" type="text" name="file" class="form-first-name form-control">
</div>
큰 문제는 함께 type
의 속성 <script>
. 당신은이 type="javascript/text"
작업에 허용되지 않는 그 무엇의를.
가벼운 메모에서 type="text"
. 무슨 뜻 type="file"
인가요?
assets/js/jquery-1.11.1.min.js
올바른 위치에 있는지 확인하십시오 .
또한 선택자와 일치하는 요소가 없습니다 #inputattrib
. 그것이 작동하지 않는 이유입니다. 다음을 사용해야합니다.
<html>
<head>
<script src="https://code.jquery.com/jquery-2.2.4.js"></script>
<title>test</title>
</head>
<body>
<div class="form-group" style="">
<p> Indicate Payment Method:</p>
<input id ="inptrue" type="radio" name="pmethod" value="Yes">Yes<br />
<input id="inpfalse" type="radio" name="pmethod" value="No">No;
</div>
<div class="form-group">
<label for="file">Upload your Payment Evidence: <i>for Bank Deposit only</i></label>
<input id="images" type="text" name="file" class="form-first-name form-control" />
</div>
<script>
$('#inptrue').click(function() {
$('#images').prop('disabled', false);
});
$('#inpfalse').click(function() {
$('#images').prop('disabled', true);
});
</script>
</body>
</html>
작업 출력 : http://output.jsbin.com/vijinukape
OP에 따라 작업 코드는 다음과 같습니다.
$('[name="pmethod"]').change(function() {
if ($(this).val() === "Yes")
$('#images').removeAttr('disabled');
else
$('#images').attr('disabled', 'disabled');
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다