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

javascript - How to get the value of the text box from a HTML Coded String - Stack Overflow

programmeradmin3浏览0评论

i have a string like

var str='<input type="text" name="se_tbox" value="Beauty is Fake" />';

I want to get only the value of that input box which is stored in str as Beauty is Fake

is there anyway to get it?

i have a string like

var str='<input type="text" name="se_tbox" value="Beauty is Fake" />';

I want to get only the value of that input box which is stored in str as Beauty is Fake

is there anyway to get it?

Share Improve this question asked Sep 24, 2010 at 8:52 RajasekarRajasekar 19k35 gold badges109 silver badges140 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 6
$(str).val(); // this would do it...

have a look

var str='<input type="text" name="se_tbox" value="Beauty is Fake" />';
alert($(str).attr('value'));
// or
alert($(str).val());

You can use jquery

$('<input type="text" name="se_tbox" value="Beauty is Fake" />').val()

or regular expression

'<input type="text" name="se_tbox" value="Beauty is Fake" />'.match(/value="([^"]*)"/)[1]

you can use this:

$(str).val();

You shouldn't stringify your HTML to process it.
But if you have to, you can use a regexp to get the value:

var val = '<input value="Beauty is Fake" />'.match(/value="([^\"]+)/)[1];
发布评论

评论列表(0)

  1. 暂无评论