最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Insert text into the inputtextarea using Jquery - Stack Overflow

programmeradmin3浏览0评论
<div class="ctrlHolder">
<label for="" id="name.label">Name</label>
<input name="name" id="name" type="text" class="textInput small" />
<p class="formHint">The name of the item you are submitting</p>
</div>

How can I insert predefined text into a input element. I'd like this function to active when the user doubleclicks the label element.

$('#name.label').dblclick(function(){
    $('#name').val('some text');
});
<div class="ctrlHolder">
<label for="" id="name.label">Name</label>
<input name="name" id="name" type="text" class="textInput small" />
<p class="formHint">The name of the item you are submitting</p>
</div>

How can I insert predefined text into a input element. I'd like this function to active when the user doubleclicks the label element.

$('#name.label').dblclick(function(){
    $('#name').val('some text');
});
Share Improve this question edited Feb 10, 2011 at 18:57 Ambo100 asked Feb 10, 2011 at 18:38 Ambo100Ambo100 1,1893 gold badges15 silver badges29 bronze badges 1
  • 2 I would be cautious to use dots in element identifiers as they may or may not confuse the jQuery selectors: #name.label matches an element that has both id="name" and class="label". – Aleksi Yrttiaho Commented Feb 10, 2011 at 19:03
Add a ment  | 

2 Answers 2

Reset to default 7

here check this fiddle

you can use .text("yourPreDefinedText") to replace the text of an element

$('#name.label') will cause jQuery to look for an element with id "name" and class "label". I believe the code above should work if you rename the label's id to something like "name-label".

发布评论

评论列表(0)

  1. 暂无评论