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

javascript - Populate input field using jQuery - Stack Overflow

programmeradmin14浏览0评论

I have a span on my page containing text, on page load, is it possible to populate an input field with this inner html using jQuery?

I've tried to setup a fiddle with my attempt only its not working...

/

I have a span on my page containing text, on page load, is it possible to populate an input field with this inner html using jQuery?

I've tried to setup a fiddle with my attempt only its not working...

http://jsfiddle/tQkaZ/

Share Improve this question asked Apr 20, 2012 at 10:05 LiamLiam 9,86340 gold badges114 silver badges214 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

You just missed the . off your first class selector. Here's an updated working fiddle.

$('hiddenfield').val( //Missing .
    $('.prodheader').html()
);​

the way you tried is correct. you just forgot to add the dot[.] before class name

$('.hiddenfield').val(
    $('.prodheader').html()
);

http://jsfiddle/tQkaZ/5/

You just forgot the class symbol in the selector. Here's the fix:

http://jsfiddle/tQkaZ/2/

$('.hiddenfield').val(
    $('.prodheader').html()
);​
发布评论

评论列表(0)

  1. 暂无评论