kullanarak textarea sonuna metin ekleme JQuery kullanarak bir textarea sonunda metin eklemeye çalışıyorum.jQuery
benim html kodu şöyle:
<textarea class='form-control' placeholder="Write something..." id="message" name="message" size='20'></textarea>
<fieldset class="form-group">
<div class="checkbox">
<label for="deptList">
<label for="departments" id="deptList">Select a department
<small>use this in case you've set up your account to <a
href="#"> include a department</a> at the end
of the text
</small>
</label>
<input type="checkbox" value="" class="checkbox-inline" id="deptCheck">
<select class="form-control" id="departments">
<option>Dept. 1</option>
<option>Dept. 2</option>
<option>Dept. 3</option>
<option>Dept. 4</option>
<option>Dept. 5</option>
<option>Dept. 6</option>
<option>Dept. 7</option>
</select>
</label>
</div>
</fieldset>
ve metin eklemek için benim senaryom:
$('#deptCheck').click(function() {
var theMessage = $("#message").text();
var theDepartment = $("#departments").find(":selected").text();
if ($(this).is(":checked")) {
console.log(theMessage + theDepartment);
$("#message").val(theMessage + theDepartment);
}else {
alert('you have included department in your text, please remove it to avoid extra charges');
}
});
şimdiye kadar: - Ben aşağı seçeneğin damlasının değeri ekleyebilirsiniz Metin alanı BUT eklediğimde, mevcut tüm metni temizler.
Elde etmek istediğim, kullanıcının metin alanında bir metin yazması, kullanıcının metin alanının altındaki açılır menüden bir seçenek seçmesi ve açılan metnin sonunda açılan metnin eklenmesidir. metin alanındaki metni. Online materyallerden denedim ama doğru anlamayacak gibi görünüyorum. Nerede yanlış gidiyorum? Burada
almak için aynı JS Fiddle
** [Bunu beğendi] (https://jsfiddle.net/Guruprasad_Rao/h2dp1oqu/9/) **? –
Önceki yanıt: http://stackoverflow.com/questions/7058864/add-text-to-textarea-jquery – sjr59