我想选择一个特定的div元素,然后将该div元素转移到一个新的html文件,以便我可以将其转换为pdf,
我的问题是我使用的是ajax,我的html代码包含各种标签,基本上它是一个管理系统,
只是为了给你一个大致的想法
$('#print_repo').on('click',function(e){
var officer_id = $('#officer-id').val();
$.ajax({
type: 'POST',
url: '<?php echo base_url(); ?>Home/ajax_view',
data: {'id':officer_id},
success: function(resp) {
// b=resp;
console.log($(resp > "#personal"));
// console.log($($(resp) >$("#personal")));
// console.log($(resp->"#personal"));
// console.log(resp);
}
});
});
这是一个ajax调用resp包含我的html代码整个html文件,包括我用过的脚本标签我要选择2个表格,其id为#s; s
是personal and work_info
例如一个
<?=form_open(base_url()."Home/insert_work_infos/","id=\"work_info\"");?>
但是我无法在resp
内选择它,resp
的输出如果我使用console.log(resp);
则是:
<div class="container-fluid">
....
<div class="content">
<div class="container-fluid">
<div class="row">
<ul class="nav nav-tabs">
<li role="presentation" id="one"class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab"><i class="fa fa-user fa-fw"></i>Home</a></li>
<li role="presentation"id="two"><a href="#profile" aria-controls="profile" role="tab"><i class="fa fa-user-plus" ></i> Profile</a></li>
<li role="presentation" id='three'><a href="#status" class="hiddd" role="tab" data-toggle="tab">Status</a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane fade in active" id="home">
<div class="container-fluid">
<div class="row">
<form action="http://project2.com/Home/insert_personal" id="personal" method="post" accept-charset="utf-8">
.................
<button id="b1" type="submit" value="Submit" class="btn btn-primary btn-inline btn-lg" tabindex="11" disabled>SUBMIT</button></div>
</form> </div>
</div>
</div>
<div role="tabpanel" class="tab-pane fade" id="profile">
<form action="http://project2.com/Home/insert_work_infos/" id="work_info" method="post" accept-charset="utf-8">
.......
........
<button type="button" onclick="javascript:back(); " data-toggle="tab" class="btn btn-default" data-target="#home">BACK</button>
</div>
<hr class="colorgraph">
<button type="submit" value="SUBMIT" id="b2"class="btn btn-primary btn-inline-block btn-lg center-block"disabled >SUBMIT</button>
</form> </div>
<script>
$(document).ready(function() {
$( ".datepicker" ).datepicker({
changeMonth: true,
changeYear: true,
// yearRange: '1950:2013',
yearRange: "c-70:c+10"
});
.......
</script>
答案 0 :(得分:2)
您可以使用find()
或filter()
方法:
$(resp).find("#personal");
//OR
$(resp).filter("#personal");
希望这有帮助。