且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery将DOM元素作为字符串

更新时间:2021-08-25 18:18:59

一个老技巧:

var selector = ":input[type=text]:first";

var str = $(selector).clone().wrap('<div/>').parent().html();

更新您无需担心拨打 .parent()因为您正在使用原始选择器的孤立克隆。

Update You don't need to worry about calling .parent() since you're working with an orphaned clone of the original selector.