2014-12-05 2 views
0

텍스트 상자에 입력하는 가장 간단한 방법은 무엇입니까? 단추를 클릭하고 텍스트 상자의 텍스트를 배열로 보내려면 어떻게해야합니까? 나는 코드가 어떻게되는지 알기 위해 물음표를 넣었지만, 나는 무엇을 확신 할 수 없다. 여기 내 코드는 다음과 같습니다각도를 사용하여 자바 스크립트 배열에 텍스트 상자 데이터 전달

내 HTML은 다음과 같습니다

<input class="textBox" style="width: 320px; color:black; margin-bottom:20px" type="text"/> 

<input class="button" style="width:100px" ng-click="addWorkflow(?,?); toggleShow('addWorkflow')" type="submit" value="Add"> 

이것은 내가 입력 한 텍스트가 가고 싶은 JS 배열, 특히 "이름"과 "설명"객체.

$scope.addWorkflow = function(newWorkflow) { 
var workflow = { 
    Id: 0, 
    Name:"This is where I want the text from the text box to appear.", 
    Description: "", 
    Lens: "", 
    Focus: "", 
    Aperture: "" 
} 
var textBox=document.getElementsByClassName("textBox")[0]; 
workflow.Name=textBox.value; 

$scope.workflows.push(workflow); 

}; 

을 그러나 당신이 당신의 입력을 주면 클래스 속성이 많은 요소에 부여하고 ID가 하나 개의 요소에 대한 특정 할 수 때문에 id="textBox"은 더 나은 것 :

$scope.addWorkflow = function(?, ?) { 
    var workflow = { 
     Id: 0, 
     Name: ?, 
     Description: ?, 
     Lens: "", 
     Focus: "", 
     Aperture: "" 
    } 

    $scope.workflows.push(workflow); 

}; 

답변

0

그럼이 시도 : 다음

<input class="textBox" id="textBox" style="width: 320px; color:black; margin-bottom:20px" type="text"/> 

그리고

사용 :

var textBox=document.getElementById("textBox"); 
workflow.Name=textBox.value; 
,

편집 :

이렇게하면 입력 된 값을 얻기 위해 할 whould 방법은 다음과 같습니다

<input class="textBox" id="name" style="width: 320px; color:black; margin-bottom:20px" type="text"/> 
<input class="textBox" id="description" style="width: 320px; color:black; margin-bottom:20px" type="text"/> 
<input class="button" style="width:100px" ng-click="addWorkflow(); toggleShow('addWorkflow')" type="submit" value="Add"> 

그런 다음 함수는 다음과 같습니다

$scope.addWorkflow = function(newWorkflow) { 
var workflow = { 
    Id: 0, 
    Name:"This is where I want the text from the text box to appear.", 
    Description: "", 
    Lens: "", 
    Focus: "", 
    Aperture: "" 
} 
var nameText=document.getElementById("name"); 
workflow.Name=nameText.value; 
var descText=document.getElementById("description"); 
workflow.Description=descText.value; 

$scope.workflows.push(workflow); 

}; 
+0

이 일을 그! 당신의 도움을 주셔서 감사합니다. – Bradston07

+0

위대한, 다행 그것은 도움이됩니다. –

+0

도움이되었지만,이 작업을 수행하는 더 간단한 방법을 찾고 있습니다. 코드가 있다는 것을 알고 있지만 내가 무엇을 알아 내지 못하는 지 물음표를 추가했습니다. – Bradston07

관련 문제