2015-01-08 5 views
0

짧은 스크립트에서 간단한 자바 스크립트 버튼 (id="storeButton")을 사용하지 않으려 고 노력했습니다. 그 효과에 대한 인터넷에서 발견 된 구문의 모든 변형을 시도했지만 아무 소용이 없습니다. 저는 이것을 워드 프레스 페이지에서 실행하고 있습니다. 누군가 내 실수를 말해 줄 수 있습니까?왜 내 버튼을 비활성화 할 수 없습니까?

워드 프레스 페이지 : 문제가 보인다

<p style="text-align: center;">Welcome!</p> 
<strong>What is this project, and why contribute?</strong> 

text 

&nbsp; 

<script src="/scripts/alert.js" type="text/javascript"></script> 
<script src="/webcamjs/webcam.js" type="text/javascript"></script> 
<script src="/scripts/take_snapshot.js" type="text/javascript"></script> 

<div class="centre" id="my_camera" style="width:320px; height:240px;"></div> 
<br> 
<div id="freezeButton"></div> 
<div id="storeButton"></div> 
<br> 
<div id="my_result"></div> 

<script type="text/javascript"> 
<!-- 
ShowAlert(); 
webcamConfigure(); 
attach(); 
createFreezeButton(); 
disableBtn(); 
createStoreButton(); 
//--> 
</script> 

take_snapshot.js이 될

document.getElementById("storeButton").disabled = true; : 당신은 "storeButton"라는 사업부를 해제하려고

function webcamConfigure(){ 
    Webcam.set({ 
     width: 320, 
     height: 240, 
     dest_width: 640, 
     dest_height: 480, 
     image_format: 'jpeg', 
     jpeg_quality: 100, 
     force_flash: true 
    }); 
} 

function attach(){ 
    Webcam.attach('#my_camera'); 
} 

function createStoreButton(){ 
    sendButton = document.createElement("input"); 
    sendButton.type = "button"; 
    sendButton.value = "Send snapshot!"; 
    sendButton.onclick = function store(){ 
     Webcam.snap(function(data_uri) { 
      document.getElementById('my_result').innerHTML = '<img src="'+data_uri+'"/>'; 
     }); 
    } 
    placeHolder = document.getElementById("storeButton"); 
    placeHolder.appendChild(sendButton); 
} 

function disableBtn(){ 
    document.getElementById("storeButton").disabled = true; 
} 

function createFreezeButton(){ 
    myButton = document.createElement("input"); 
    myButton.type = "button"; 
    myButton.value = "Take snapshot!"; 
    myButton.onclick = function freeze(){ 
     if (myButton.value=="Take snapshot!") { 
      myButton.value = "Discard snapshot!"; 
      Webcam.freeze(); 
      //document.getElementById("storeButton").disabled = false; 
     } 
     else { 
      myButton.value = "Take snapshot!"; 
      Webcam.unfreeze(); 
      //document.getElementById("storeButton").disabled = true; 
     } 
    } 
    placeHolder2 = document.getElementById("freezeButton"); 
    placeHolder2.appendChild(myButton); 
} 

답변

1

, 해당 div 안에 포함 된 만든 단추를 비활성화하는 대신 이 도움이

var sendButton; 
function webcamConfigure(){ 
    Webcam.set({ 
     width: 320, 
     height: 240, 
     dest_width: 640, 
     dest_height: 480, 
     image_format: 'jpeg', 
     jpeg_quality: 100, 
     force_flash: true 
    }); 
} 

function attach(){ 
    Webcam.attach('#my_camera'); 
} 

function createStoreButton(){ 
    sendButton = document.createElement("input"); 
    sendButton.type = "button"; 
    sendButton.value = "Send snapshot!"; 
    sendButton.onclick = function store(){ 
     Webcam.snap(function(data_uri) { 
      document.getElementById('my_result').innerHTML = '<img src="'+data_uri+'"/>'; 
     }); 
    } 
    placeHolder = document.getElementById("storeButton"); 
    placeHolder.appendChild(sendButton); 
} 

function disableBtn(){ 
    sendButton.disabled = true; 
} 

희망,

: 데이비드

을 : 당신이 그것을 사용하지 않을 때 상황에서 그렇게 할 수있는 간단한 방법은 버튼을 만들 때 공공 VAR을 가지고, 즉 볼 수 있습니다
+0

나는 그것을 시도했다. 방금 재 시도했지만 여전히 아무 일도 일어나지 않습니다. 그래도 의견을 보내 주셔서 감사합니다! 이것이 WordPress와 관련이 있다면 궁금해하니 ?? – Raoul

0

글쎄, 누군가가 일시적으로 downvoted 답변을 내 버튼이 작동하지만, 그 CSS가 부족하다는 것을 게재 게시했습니다. 그것은 완전히 정답은 아니었지만 올바른 포인트를 가지고있는 것 같습니다. (이 글을 읽고 계신다면 이전 답변자 인 답을 다시 게시하면됩니다.)

난 정말 내가 여기, 뭘하는지 모르겠어요 ... 그리고 내 코드의 구조가 그래서 여기, 그러나 그것은 작동, 확실히 JS의 신에 대한 모독이다 간다 :

var sendButton; 
var freezeButton; 

function webcamConfigure(){ 
    Webcam.set({ 
     width: 320, 
     height: 240, 
     dest_width: 640, 
     dest_height: 480, 
     image_format: 'jpeg', 
     jpeg_quality: 100, 
     force_flash: true 
    }); 
} 

function attach(){ 
    Webcam.attach('#my_camera'); 
} 

function createStoreButton(){ 
    sendButton = document.createElement("input"); 
    sendButton.type = "button"; 
    sendButton.value = "Send snapshot!"; 
    sendButton.disabled = true; 
    sendButton.onclick = function store(){ 
     Webcam.snap(function(data_uri) { 
      document.getElementById('my_result').innerHTML = '<img src="'+data_uri+'"/>'; 
     }); 
     freezeButton.value = "Take snapshot!" 
     sendButton.disabled = true; 
    } 
    placeHolder = document.getElementById("storeButton"); 
    placeHolder.appendChild(sendButton); 
} 

function createFreezeButton(){ 
    freezeButton = document.createElement("input"); 
    freezeButton.type = "button"; 
    freezeButton.value = "Take snapshot!"; 
    freezeButton.onclick = function freeze(){ 
     if (freezeButton.value=="Take snapshot!") { 
      freezeButton.value = "Discard snapshot!"; 
      Webcam.freeze(); 
      sendButton.disabled = false; 
     } 
     else { 
      freezeButton.value = "Take snapshot!"; 
      Webcam.unfreeze(); 
      sendButton.disabled = true; 
     } 
    } 
    placeHolder2 = document.getElementById("freezeButton"); 
    placeHolder2.appendChild(freezeButton); 
} 
관련 문제