清算后无法附加到textarea

时间:2017-03-30 13:29:08

标签: javascript jquery html

我有一个下拉选择,可以在更改时附加到文本区域。我设置了一个简单的按钮来清除它有效,但后来我无法从下拉列表中重新添加。

小提琴:https://jsfiddle.net/kreza/noy5gqfL/6/

jquery片段:

$('#criteriaSelect').change(function () {
    $('#inputCriteria').append((this.value + ';' + '\n'));
});
$('#clearTextArea').click(function () {
    $('#inputCriteria').val('');
});

我做错了什么?

3 个答案:

答案 0 :(得分:4)

尝试此方法$('#inputCriteria')。empty();

答案 1 :(得分:2)

textareas中的

值使用.val()设置。试试这个:

$('#criteriaSelect').change(function () {
    $('#inputCriteria').val((this.value + ';' + '\n'));
});
$('#clearTextArea').click(function () {
    $('#inputCriteria').val('');
});

答案 2 :(得分:1)

像这样使用$('#inputCriteria').val($('#inputCriteria').val()+$(this).val() + ';' + '\n');

请勿使用append.to以避免input,textarea标记

中的追加事件

$('#criteriaSelect').change(function () {

		$('#inputCriteria').val($('#inputCriteria').val()+$(this).val() + ';' + '\n');
    });
$('#clearTextArea').click(function () {
    $('#inputCriteria').val('');
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<select type="text" class="form-control" id="criteriaSelect">
  <option disabled selected>Select One:</option>
  <option value="AASHTO">AASHTO Roadside Design Guide</option>
  <option value="RAMCAP">AWWA Risk and Resilience Management of Water and Wastewater Systems (RAMCAP)</option>
  <option value="CDOT DDM">CDOT Drainage Design Manual</option>
  <option value="CDOT MSS">CDOT M&S Standards</option>
  <option value="CDOT SSRBD">CDOT Standard Specifications for Road and Bridge Construction</option>
  <option value="CHPHE DWTW">CHPHE Design Criteria for Domestic Wastewater Treatment Works</option>
  <option value="CDPHE PWS">CDPHE Design Criteria for Potable Water Systems</option>
  <option value="CWCB FSCM">CWCB Floodplain Stormwater and Criteria Manual</option>k
  <option value="FHWA FIRBD">FHWA Framework for Improving Resilience of Bridge Design</option>
  <option value="FHWA Highways">FHWA Highways in the River Environment- Floodplains, Extreme Events, Risk and Resilience</option>
  <option value="FHWA CRBFHP">FHWA Standard Specs for Construction of Roads and Bridges on Federal Highway Projects</option>
  <option value="UDFCD USD">UDFCD Urban Storm Drainage Criteria Manuals</option>
  <option value="DSDM">Rules and Regulations for Dam Safety and Dam Construction</option>
  <option value="Other">Other Manuals Used</option>
</select>
<label for="inputCriteria" class="control-label">Select from drop-down:</label>
<textarea class="form-control" rows="3" id="inputCriteria" style="resize: none;" disabled></textarea>
<button class="btn-danger col-sm-2" id="clearTextArea">Clear</button>