2015-01-01 3 views
-1

콘텐츠 및 스크립트가 작동 중일 때 CSS (나중에 나오는 CSS), JavaScript 및 Ajax를 사용하여 (게임 Terraria 용) TShock 서버를 관리하는 웹 페이지를 만들고 있습니다. 그것의 REST API."사용 안 함"입력을 사용하지 않도록 설정했습니다.

페이지가 모든 REST API 끝점 (대부분 사용 가능)을 지원할 수 있도록하려는 경우 (목록 사용 가능 : here).

현재 /v2/users/update 끝점 부분에 문제가 있습니다. 양식을 만들고 싶습니다. (<form> 태그를 사용하지 않고, '대 - 자 키보드 인터페이스가'입력 '키와 일치하지 않기를 바랍니다.)

엔드 포인트의 설명에 따르면 선택 필드는 passwordgroup입니다. 적어도 하나를 제공하지 않으면 사용자 업데이트 시점을 무력화시킬 것입니다.

하나 또는 둘 모두가 제공되었는지 확인하려면 확인란과 라디오 버튼을 사용하고 싶습니다 (다시 의자 대 키보드 인터페이스 때문).

각 라디오 버튼은 올바른 입력 필드를 사용하도록 설정되어 있습니다 (예외는 제외). Chrome의 콘솔은 Firefox와 IE를보고하지 않습니다.

누구에게도이 대안이 있습니까? 물론, 나는 실수를 범할 수 있었다.

나는 사용자의 선택에 따라 divinnerHTML을 변경하는 것을 피하고 싶습니다.


JS 코드 (jQuery를 사용하여 코드 예제) :

function PassInputOnly(){ 
    $.("#PwdField").prop("disabled", false); // Using document.getElementById("FieldId").disabled 
    $.("#GrpField").prop("disabled", true); // doesn't work either. 
} 

function GrpInputOnly(){ 
    $.("#PwdField").prop("disabled", true); 
    $.("#GrpField").prop("disabled", false); 
} 

function BothInputs(){ 
    $.("#PwdField").prop("disabled", false); 
    $.("#GrpField").prop("disabled", false); 
} 

HTML 코드 :

<input type="text" id="UpdUser" placeholder="Username"> 
<p>What will get updated ?</p> 
<input type="radio" name="WhatGetsUpdated" onclick="BothInputs()" checked>Password and Group<br> 
<input type="radio" name="WhatGetsUpdated" onclick="PassInputOnly()">Password<br> 
<input type="radio" name="WhatGetsUpdated" onclick="GrpInputOnly()">Group<br> 
<input type="text" id="PwdField" placeholder="New password"> 
<input type="text" id="GrpField" placeholder="New group"> 

참고 : 나는, on* 이벤트를하지 사용할하지만 그것은 this question 유사하다 값.

+2

'$ ("#의 PwdField")''$ ("#의 PwdField") '등을해야한다 .. –

답변

1

"." . $ 즉

$.("#PwdField") ==> $("#PwdField") 

에 체크 아웃 후 :

function PassInputOnly(){ 
 
    
 
    $("#PwdField").prop("disabled", false); // Using document.getElementById("FieldId").disabled 
 
    $("#GrpField").prop("disabled", true); // doesn't work either. 
 
} 
 

 
function GrpInputOnly(){ 
 
    $("#PwdField").prop("disabled", true); 
 
    $("#GrpField").prop("disabled", false); 
 
} 
 

 
function BothInputs(){ 
 
    $("#PwdField").prop("disabled", false); 
 
    $("#GrpField").prop("disabled", false); 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
 
<input type="text" id="UpdUser" placeholder="Username"> 
 
<p>What will get updated ?</p> 
 
<input type="radio" name="WhatGetsUpdated" onclick="BothInputs()" checked>Password and Group<br> 
 
<input type="radio" name="WhatGetsUpdated" onclick="javascript:PassInputOnly()">Password<br> 
 
<input type="radio" name="WhatGetsUpdated" onclick="GrpInputOnly()">Group<br> 
 
<input type="text" id="PwdField" placeholder="New password"> 
 
<input type="text" id="GrpField" placeholder="New group">

+0

예. Chair-to-keyboard 인터페이스 오류. 감사. –

관련 문제