2015-01-29 5 views
0

나는 자바 스크립트를 안다. 작은 스크립트를 결합하여 &을 변환하여 대부분의 요구 사항을 달성했습니다. 그러나 아래에 설명 된 요점에서 나는 나의 요구 사항을 완전히 해결할 수 없었다.

내 상수 텍스트 앞에 하이퍼 링크 ID 값을 인쇄하려고합니다.jquery를 사용하지 않습니다. 단지 쓰고 당분간 예

"당분간로 응답하고있다."

단 (하이퍼 링크 ID = 6을 가정)는 6의해 회신되는 "작성해야 당분간 "

내가 읽은이 SO Q & A 그러나 나는 그것으로부터 이익을 얻을 수 없었다. 당신이 LinkId.value = id톤을 추가 결코처럼 몸 태그 (JS: How to concatenate variables inside appendChild()?)

DEMO FOR THE CURRENT STATE @JSFIDDLE

JS

function reply_comment (id) { 
    var LinkId = document.getElementById('parent_id');  
    LinkId.value = id; 
    var message = document.createTextNode(" is being replied by the time being."); 
    document.getElementById('print_id').appendChild(message); 
    document.getElementById("focus_id").focus(); 
} 

HTML은 나에게

<!-- codes given above --> 
<script type="text/javascript"> 
... ... ... 
</script> 
<!-- codes given above --> 

<!-- when clicked on the hyperlink, store the hyperlink id value (id value is an unsigned integer) --> 
<!-- print the stored id from hyperlink into the value="{unsigned integer id}" part of input (type:text and id="parent_id")--> 
<!-- focus on comment form's input (type:text and id="focus_id") --> 
<!-- print preset message between span tags (span tag id="print_id" ) --> 


<a class="rep" href="#focus_id" onclick="reply_comment(this.id);" id="6" rel="nofollow">reply comment</a> 
<p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p><p>filling words</p> 
<span id="print_id"></span> 
<form> 
    <label for="focus_id">Focus the cursor below</label> 
    <input type="text" id="focus_id" name="focus_id"> 
    <label for="parent_id">Paste parent_id below</label> 
    <input type="text" id="parent_id" name="parent_id" value=""> 
</form> 

답변

0

그것은 본다 오 당신 message :

function reply_comment (id) { 
    var LinkId = document.getElementById('parent_id');  
    LinkId.value = id; 
    var message = document.createTextNode(id + " is being replied by the time being."); 
    document.getElementById('print_id').appendChild(message); 
    document.getElementById("focus_id").focus(); 
} 

바이올린 : http://jsfiddle.net/fiddle_me_this/nc43vypp/5/

내가했던 모든 방금 + 연산자를 사용하여 연결할하기 위해에서

" is being replied by the time being."의에 id +을 추가했다. 당신은 많은 것들을 연결할 수 있습니다. 예 : var string = "MY " + "CONCATENATED " + " STRING";"MY CONCATENATED STRING"을 출력합니다. 등등.

+0

나는 JS에 대해 무지하다는 말을했습니다. 감사합니다. –