2017-12-30 6 views
1

, 나는이 같은 5 개 이상의 텍스트 영역 :선택 내용 당신은 할 때 더 내 HTML 문서에

<textarea name="comente5422" id="comente5422" placeholder="Tap your coment..."></textarea> 

당신은 텍스트 영역을 보듯이 ID : comente5422 등의 숫자 변화

comente5423, comente5424, ...

그리고이 내용을 얻을 수있는 JS 스크립트입니다 :이 같은 각 텍스트 영역과 매우 바쁜 될 HTML 코드의 ID를 사용할 때 각 텍스트 영역에서 그것을 duplicat 때 탭에 버튼

<script type="text/javascript">$('#comente').keypress(function(event) { 

    if (event.keyCode == 13 || event.which == 13) { 

var blae = $('#comente').val(); 
var is_ownn = $('#son_owni').text(); 

    $.ajax({      
       type: 'post', 
       url: 'call.php', // point to server-side PHP script 
       data: { 
      coment: blae<?php echo $publication['id_share'];;?>, 
      is_own: is_ownn<?php echo $publication['id_share'];;?>, 
     }, 
       success: function(scrip_response){ 

       } 
    }); 
    } 
});</script> 

이 스크립트 작업을 입력합니다.

이 스크립트를 복제하지 않고도 텍스트 영역의 내용을 가져 오는 다른 방법이 있는지 알고 싶습니다! 당신의 콘텐츠를 할 때 이름을 선택하고 this .If 이름을 사용할 수 있습니다

답변

1

이 다른, 다음 공통 클래스를

$("textarea[name='comente5422']").keypress(function(event) { 
if (event.keyCode == 13 || event.which == 13) { 
var blae = $(this).val(); 
var is_ownn = $('#son_owni').text(); 
//... rest of code 

를 사용하거나 또한 attribute-starts-with-selector

$("textarea[id^='comente']").keypress(function(event) { 
    if (event.keyCode == 13 || event.which == 13) { 
    var blae = $(this).val(); 
    var is_ownn = $('#son_owni').text(); 
    //... rest of code 
+0

확인을 사용할 수 있지만 그 양식 안에있는 INPUT은 어떻게 할 수 있습니까? – Sylarman5

관련 문제