简体   繁体   中英

How to load a file content in a text area using $?

i would like to show a style sheet content in a text area is a user select a style in select box. The style sheet is in server so i tried load and get both doesn't work form me.

<script type="text/javascript">
    jQuery(document).ready(function(){
    jQuery('#sel').change(function() { 
     jQuery.get('style1.css',function(data) {
     jQuery('#cs').html(data);
     alert('Load was performed.');
     });

   // jQuery('#cs').load('style1.css'); 

    }); 
});
    </script> 

Html

<select id="sel">
 <option value="style1">style1</option>
 <option value="style2">style2</option>
</select>

I'm getting load was performed alert but not the content in the text area.

Here #cs is the id of my text area.

使用val()而不是html()设置textarea的值。

You need to use val.

jQuery(document).ready(function(){
    jQuery('#sel').change(function() { 
     jQuery.get('style1.css',function(data) {
     jQuery('#cs').val(data);
     alert('Load was performed.');
     });

   // jQuery('#cs').load('style1.css'); 

    }); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM