使用qtip2调用后台的程序,却发现无法取不到html元素的值,代码如下
script部分
<script type="text/javascript" src="js/jquery.qtip/jquery.qtip.min.js"></script>
<link rel="stylesheet" href="js/jquery.qtip/jquery.qtip.min.css">
<script>
$(document).ready(function(){
alert( $(".demo1").text());
//带关闭按钮的提示 且延时3秒关闭
$(".demo1").qtip({
content: {
text: "loading...",
ajax: {
url: 'test.action',
type: 'POST',
data: {
title: **$(this).html()**
},
dataType: 'text',
success: function(){
alert($(this).html());
}
},
title: "提示标题",
button: "关闭"
},
hide: {
event: false, //设置不自动关闭 可配合inactive组合使用
inactive: 3000 //设置延时关闭
},
style: {
//换样式 阴影 圆角叠加
classes: 'qtip-light qtip-shadow qtip-rounded'
},
position: {
my: 'bottom left',
at: 'top center'
}
});
});
</script>
html部分
<div style="margin-top:200px;">
<span class="demo1">Glioblastoma and Gliomas</span>
</div>
这样的结果可以调用后台但发现传入的值是null,所以在success中调用alert,发现alert出来的也是空,那么就是$(this).html()的取值问题了
请问有什么解决方案? 希望大侠们不吝赐教
你那样传递title,this是window对象,你要传递什么内容不直接获取需要的控件的html就行了
data: {
title: $(".demo1")
}