先前选择的值也附加在textarea中,但我只希望一个(当前)选择的值附加在textarea中 [英] previous selected value also append in textarea but i want only one (current) selected value append in textarea
本文介绍了先前选择的值也附加在textarea中,但我只希望一个(当前)选择的值附加在textarea中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
先前选择的值也附加在textarea中,但我只希望一个(当前)选择的值附加在textarea中
previous selected value also append in textarea but i want only one (current) selected value append in textarea
$(document).ready(function() {
$(document).click("click", function(e) {
if ((e.target.value != undefined) && (e.target.id == "checkit")) {
if ((e.target.id != "if") && (e.target.id != "while")) {
$('#sms_text').val($('#sms_text').val() + e.target.value + '\n');
}
}
});
// second
$('#mc_nos').change(function() {
if ($('#mc_nos option:selected')) {
$("#mc_nos option:selected").addClass("important");
}
});
$(document).change("change", function(e) {
if ((e.target.value != undefined) && (e.target.id == "mc_nos")) {
if ($("#mc_nos option:selected")) {
$(this).find("option:selected").each(function() {
if ($(this).attr("class") == "important") {
$('#sms_text').val(e.target.value + '\n' + $('#sms_text').val());
}
});
}
}
});
});
我想同时在两个左侧按钮(屏幕快照)上附加值并选择框选项值.
i want to append values both leftside buttons(screenshot) and select box option values.
选择框选项值仅附加一个当前选择的选项
select box option values only append one current selected option
推荐答案
由于我不知道您的HTML外观如何,我只是在解决您的问题并创建了一个演示..请检查
Hi since i dont know how your HTML looks like I am just addressing your question and have created a demo.. kindly check https://jsfiddle.net/hscrhokc/2/
已更新 https://jsfiddle.net/hscrhokc/7/
HTML
<select class="dd">
<option>1111111111</option>
<option>6666666666</option>
<option>7777777777</option>
<option>8888888888</option>
<option>9999999999</option>
</select>
<div class="menu">
<span>some text1</span>
<span>some text2</span>
<span>some text3</span>
<span>some text4</span>
</div>
<br>
<textarea class="ta">
fdsfdsf
ewqew
bnmnmnm
</textarea>
jQuery
$(document).ready(function(){
$('.menu').on('click', 'span', function(){
$('.ta').prepend($(this).text()+'\n');
});
$('.dd').on('change', function(){
var taVal= $('.ta').text(); // store textara text in a variable
var taArr=taVal.split("\n"); // split string into words and store it as an array taArr
// traverse throug the dropdown
$('.dd option').each(function(i){
// check whether the dropdown value exists in textarea text
if($.inArray(this.value,taArr)!=-1){
$('.ta').text(taVal.replace(this.value+'\n', '')); // if found remove it
}
});
//prepend the selected dropdown value to textarea
$('.ta').prepend($('.dd').val()+'\n');
});
});
这篇关于先前选择的值也附加在textarea中,但我只希望一个(当前)选择的值附加在textarea中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文