如何从elementByid向占位符写入文本?

时间:2014-12-09 15:24:51

标签: javascript jquery input getelementbyid

如何从占位符中写入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

之后

1 个答案:

答案 0 :(得分:0)

您可以更新占位符以附加标签文本,如下所示。

&#13;
&#13;
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;
&#13;
&#13;