jquery弹出显示json
我是jquery的新手,我想在jquery弹出窗口中显示json,但它无法工作 以下是我的功能:jquery弹出显示json,jquery,yii,Jquery,Yii,我是jquery的新手,我想在jquery弹出窗口中显示json,但它无法工作 以下是我的功能: $(document).ready(function(){ $(".popup").click(function(){ var value = $(this).attr("value"); $.post("/news/index.php?r=news/detail&id="+value,function(data,status){
$(document).ready(function(){
$(".popup").click(function(){
var value = $(this).attr("value");
$.post("/news/index.php?r=news/detail&id="+value,function(data,status){
if(data != null){
$( "#dialog-message" ).dialog({
modal: true,
buttons: {
Ok: function() {
$( this ).dialog( "close" );
}
}
});
}
});
});
});
值data={'title':test,'description':description}
如何在弹出窗口上显示“测试”和“说明”。
非常感谢试试这个。。为了使用.dialog函数,您还需要包含jquery.ui库
//html
<div id="dialog-message" title="Basic dialog">
<div id="title"></div>
<div id="description"></div>
</div>
//javascript
if(data != null){
$('#title').text(data.title);
$('#description').text(data.description);
$( "#dialog-message" ).dialog({
modal: true,
buttons: {
Ok: function() {
$( this ).dialog( "close" );
}
}
});
}
//html
//javascript
如果(数据!=null){
$('#title').text(data.title);
$('#description').text(data.description);
$(“#对话框消息”).dialog({
莫代尔:是的,
按钮:{
好的:函数(){
$(此).dialog(“关闭”);
}
}
});
}
对话框由三部分组成:页眉、内容和页脚。您需要获取content元素并将JSON附加到某个子元素
您可以在对话框/内容部分中配置打开的函数和抓取与元素:
$("#dialog-message").dialog({
open: function( event, ui ) {
$(this).find('.ui-dialog-content').text(JSON.stringify(yourObject));
}
});
在本例中,$(this)表示用于创建对话框的选择器,在本例中,它表示$('#dialog message')元素。因此,在此之后,您可以检查您的对话框,查看子内容是什么,并找到要添加到JSON对象中的特定元素
请参见此处的“打开”方法或“打开”事件的文档您可以通过设置对话框消息元素的“title”属性来设置对话框标题。您可以通过在
#对话框消息
元素中放置文本来设置对话框内容
if (data != null) {
$("#dialog-message").prop('title', data.title).text(data.description).dialog({
modal: true,
buttons: {
Ok: function () {
$(this).dialog("close");
}
}
});
}
测试和描述从何而来?您的代码中没有提到这一点?在弹出窗口中显示JSON的原因是什么?它只是为了测试目的吗?如果是这样,您应该改用
console.log(jsonObject)