简体   繁体   中英

jQuery : Append text after an input field

I have a simple input field :

<input type="text" id="someid" name="somename" class="someclass">

I'm trying to append some link right after this; so i'll get :

<input type="text" id="someid" name="somename" class="someclass"> - <a href="#">..</a>

i tried :

$("input#someid.someclass").append(' - <a href="#">Are you sure  ?</a>');

Without success, must be stupid but i can't find out what's wrong.

使用after而不是append

$("input#someid.someclass").after(' - <a href="#">Are you sure  ?</a>');

试试.after()代替:

$("input#someid.someclass").after(' - <a href="#">Are you sure  ?</a>');

The append method will add the node you give it to the element you call it on.

In your case, you are putting the HTML inside the INPUT element.

You need to use the after method to insert the HTML after your INPUT element.

$("input#someid.someclass").after($('<a>')
                           .attr('href','#').text('Are you sure  ?'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM