bev*_*qua 18 javascript jquery
说我有
$(":input[type=text]:first")
Run Code Online (Sandbox Code Playgroud)
如何得到
<input type="text" value="" size="28" maxlength="140" tabindex="1" placeholder="search" class="textbox" name="q" autocomplete="off">
Run Code Online (Sandbox Code Playgroud)
假设我在SO上运行它?
更新我不想打电话,.parent()
因为我在父元素中有很多其他东西.
Bla*_*ger 22
var selector = ":input[type=text]:first";
var str = $(selector).clone().wrap('<div/>').parent().html();
Run Code Online (Sandbox Code Playgroud)
更新您不必担心调用,.parent()
因为您正在使用原始选择器的孤立克隆.
通过附加到创建的元素来使用jQuery.html()。
$('<div/>').append($(":input[type=text]:first").clone()).html()
Run Code Online (Sandbox Code Playgroud)
这是一个提供示例的小提琴:http : //jsfiddle.net/Zwbmx/1/
归档时间: |
|
查看次数: |
31283 次 |
最近记录: |