如何从占位符中写入elementByid的文本?
相关ID中的文字:
function friendMessage(jqEvent){
$('#labelTo').text(jqEvent.attr('friendName'));
}
占位符:
<input type="text" name="to" class="required char-countable1 msg" maxlength="250" placeholder="To: " >
文本应显示在To
之后答案 0 :(得分:0)
您可以更新占位符以附加标签文本,如下所示。
function friendMessage(jqEvent){
var input = $('input.required.char-countable1.msg');
input.attr('placeholder', input.attr('placeholder') + $('#labelTo').text());
}
friendMessage();
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label id="labelTo">test value</label>
<input class="required char-countable1 msg" placeholder="To: "/>
&#13;