开发者

How to get the value of the text box from a HTML Coded String

i have a string like

var str='<input type="text" nam开发者_JAVA百科e="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?


$(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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜