Nice programing

일반 텍스트 영역

nicepro 2021. 1. 9. 11:40
반응형

일반 텍스트 영역


Onselect 이벤트에는 스크립트가 있습니다.

$("#vinanghinguyen_images_bbocde").val('');
$("#vinanghinguyen_images_bbocde").val(vinanghinguyen_final_bbcode);

값을 추가하기 전에 일반 텍스트 영역 id = "vinanghinguyen_images_bbocde"를 원합니다. 그러나 textarea add add add add and value and not clear. 가치를 추가하기 전에 지우고 싶습니다.

여기서 uploadify를 사용하는 것은 내 기능입니다.

<script type = "text/javascript" >
  $(document).ready(function() {
    vinanghinguyen_bbcode = '';
    vinanghinguyen_final_bbcode = '';
    vinanghinguyen_link = '';
    vinanghinguyen_final_derect_link = '';
    response = '';

    $('#file_upload').uploadify({
      'uploader'  : '{SITE_FULL_URL}/uploadify/uploadify.swf',
      'script'    : '{SITE_FULL_URL}/uploadify/uploadify.php',
      'cancelImg' : '{SITE_FULL_URL}/uploadify/cancel.png',
      'folder'    : 'data/picture_upload/2011',
      'auto'      : false,
      'multi'     : true,
      'buttonText': '',

      'onComplete': function(event, ID, fileObj, response, data) {
        vinanghinguyen_bbcode = '[IMG]' + 'http://cnttvnn.com' + response + '[/IMG]' + '\n';
        vinanghinguyen_final_bbcode = vinanghinguyen_final_bbcode + vinanghinguyen_bbcode;
        vinanghinguyen_derect_link = 'http://cnttvnn.com' + response + '\n';
        vinanghinguyen_final_derect_link = vinanghinguyen_final_derect_link + vinanghinguyen_derect_link;

        $("#vinanghinguyen_images_bbocde").val('').val(vinanghinguyen_final_bbcode);
      //$("#vinanghinguyen_images_derect_link").val(vinanghinguyen_final_derect_link);
        $("#vinanghinguyen_result").show();
        $(".uploadifyQueue").height(5);
      },

      'onSelect': function(event, ID, fileObj) {
        $("#vinanghinguyen_images_bbocde").val('');
        $("#vinanghinguyen_result").hide();
        $(".uploadifyQueue").height(315);
      },
    });
  });
</script>

을 수행 $("#vinanghinguyen_images_bbocde").val('');하면 텍스트 영역의 모든 내용이 제거되므로 문제가 발생하지 않으면 다른 곳에서 문제가 발생할 수 있습니다.

제공 한 예제가 작동하므로 코드의 조금 더 큰 부분을 게시하면 도움이 될 수 있습니다.


사용 $('textarea').val('').

사용의 문제는 $('textarea').text(''), 또는 $('textarea').html('')그 문제에 관해서는 단지 서버에서 전송 한 원래의 DOM에 무엇 지울 것입니다. 사용자가이를 지운 다음 새 입력을 입력하면 지우기 버튼이 더 이상 작동하지 않습니다. 사용 .val('')은 사용자 입력 케이스를 올바르게 처리합니다.


이것은 작동합니다 :

$('#textareaName').val('');

This method removes not only child (and other descendant) elements, but also any text within the set of matched elements. This is because, according to the DOM specification, any string of text within an element is considered a child node of that element.

$('textarea').empty()

try this

 $("#vinanghinguyen_images_bbocde").attr("value", ""); 

Try this,

$('textarea#textarea_id').val(" ");

I just tried using this code and @psynnott's answer was correct though I needed to know it would work repeatedly, seems to work with jquery 1.7.1 >

I modified the jfiddle to the following http://jsfiddle.net/Rjj9v/109/

$('#mytext').text('');

This is not a new answer @psynnott is correct I am just providing a more concise example that shows the textarea is still working after the clear because if you use .val("") the text area stops working


Correct answer is: $("#selElement_Id option:selected").removeAttr("selected");


I agree with @Jakub Arnold's answer. The problem should be somewhere else. I could not figure out the problem but found a work around.

Wrap your concerned element with a parent element and cause its html to create a new element with the id you are concerned with. See below

<div id="theParent">
    <div id="vinanghinguyen_images_bbocde"></div>
</div>

'onSelect'    : function(event,ID,fileObj) {
 $("#theParent").html("<div id='vinanghinguyen_images_bbocde'></div>");
 $("#vinanghinguyen_result").hide();
 $(".uploadifyQueue").height(315);
}

I believe the problem is simply a spelling error when writing bbcode as bbocde:

$("#vinanghinguyen_images_bbocde").val('')

should be:

$("#vinanghinguyen_images_bbcode").val('')

Rather simpler method would be by using JavaScript method of innerHTML.

document.getElementById("#id_goes_here").innerHTML = "";

Rather simpler and more effective way.

   

ReferenceURL : https://stackoverflow.com/questions/8284960/clear-text-area

반응형