Javascript .对话框未显示在表格单元格上单击

Javascript .对话框未显示在表格单元格上单击,javascript,jquery,ajax,xml,Javascript,Jquery,Ajax,Xml,更新:我目前被这段代码卡住了,单击时没有显示对话框: 现在的问题是,当点击标题时,什么都不会发生。有什么想法吗?当我去掉.hidden css类时,数据就在那里,我可以看到它 $(".showRow").click(function(){ descId= $(this).data('id'); $('#desc_'+descId).dialog({ modal: true, width: 500 }); }); 我正在制作一个电视指南,

更新:我目前被这段代码卡住了,单击时没有显示对话框: 现在的问题是,当点击标题时,什么都不会发生。有什么想法吗?当我去掉.hidden css类时,数据就在那里,我可以看到它

$(".showRow").click(function(){
    descId= $(this).data('id');
    $('#desc_'+descId).dialog({
        modal: true,
        width: 500
    });

});
我正在制作一个电视指南,当标题点击单元格时,我希望弹出一个带有标题描述的窗口,但是我只能显示所有的描述,而不仅仅是与标题匹配的单个描述,我该怎么做

HTML


StartEndTitle
隐藏的{
显示:无;
}
jQuery

 $.ajax({
        url: "xml/tvguide.xml" ,
        dataType: "xml" ,
        type: "GET",
        success: function(data) {
            rowNum = 1;
            $(data).find('tvguide channel[id="bbconemonday"] programme').each(function() {

            var title = $(this).find('title').text();
            var desc = $(this).find('desc').text();
            var start = $(this).find('start').text();
            var end = $(this).find('end').text();
            $('<tr data-id="'+rowNum+'" class="showRow"></tr>').html('<td>'+start+'</td><td>'+end+'</td><td title="'+desc+'">'+title+'<div class="hidden" id="desc_'+rowNum+'">'+desc+'</div></td>').appendTo('#chart');
            rowNum++

        });
$.ajax({
url:“xml/tvguide.xml”,
数据类型:“xml”,
键入:“获取”,
成功:功能(数据){
rowNum=1;
$(数据)。查找('tvguide频道[id=“bbconemonday”]节目')。每个(函数(){
var title=$(this.find('title').text();
var desc=$(this.find('desc').text();
var start=$(this.find('start').text();
var end=$(this.find('end').text();
$('').html(''+start+''+end+''+title+''+desc+'').appendTo(''#chart');
罗努姆++
});
XML示例

    <tvguide>
    <channel id="bbconemonday">
    <programme>
<desc>
The latest news, sport, business and weather from the BBC's Breakfast team. Also in HD. [S] Including regional news at 25 and 55 minutes past each hour.
</desc>
<title>Breakfast</title>
<end>0915</end>
<start>0600</start>
 </programme>
 <programme>
<desc>
13/20. Matt Allwright investigates the activities of conmen, revealing the fake batteries being used in mobile phones, cameras and laptops. Also in HD. [S]
</desc>
<title>Fake Britain</title>
<end>1000</end>
<start>0915</start>
 </programme>
 <programme>
<desc>
Martin Roberts and Lucy Alexander visit a cottage in Devon, a ground floor flat in London and a house in Lancashire. They find out how much each went for at auction. [S]
</desc>
<title>Homes Under the Hammer</title>
<end>1100</end>
<start>1000</start>
 </programme>
 <programme>
<desc>
8/10. Series which sees insurance fraudsters caught on camera. A convicted drug dealer thinks a bump on the head will give him a bumper payout. Also in HD. [S]
</desc>
<title>Claimed and Shamed</title>
<end>1130</end>
<start>1100</start>
 </programme>
 <programme>
<desc>
8/10. Documentary following life on the English Channel. A band of eco-fishermen from Weymouth help preserve the channel's fish stocks by using traditional fishing methods. Also in HD. [S]
</desc>
<title>Channel Patrol</title>
<end>1215</end>
<start>1130</start>
 </programme>
 <programme>
<subtitle>Horncastle</subtitle>
<desc>
Tim Wonnacott and the teams hunt for bargains in the historic town of Horncastle, and Tim pays a visit to the Birmingham Museum and Art Gallery. Also in HD. [AD,S]
</desc>
<title>Bargain Hunt</title>
<end>1300</end>
<start>1215</start>
 </programme>
<programme>
<desc>
The latest national and international news stories from the BBC News team, followed by weather. Also in HD. [S]
</desc>
<title>BBC News at One</title>
<end>1330</end>
<start>1300</start>
</programme>
<programme>
<desc>
The latest news, sport and weather from London. [S]
</desc>
<title>BBC London News</title>
<end>1345</end>
<start>1330</start>
</programme>
<programme>
<subtitle>Victim</subtitle>
<desc>
Drama series. A seemingly straightforward home visit takes an incredibly dark turn for Niamh. The documentary filming doesn't go to plan for Howard. Also in HD. [AD,S]
</desc>
<title>Doctors</title>
<end>1415</end>
<start>1345</start>
</programme>
<programme>
<desc>
8/10. The Ties of the Past: A life model is found murdered at the start of a painting class. Also in HD. [AD,S]
</desc>
<title>The Doctor Blake Mysteries</title>
<end>1510</end>
<start>1415</start>
</programme>
<programme>
<subtitle>West of Scotland</subtitle>
<desc>
Nicki Chapman travels through the west of Scotland, helping an animal-loving couple find their perfect country home. While there, Nicki tries her hand at curling. Also in HD. [AD,S]
</desc>
<title>Escape to the Country</title>
<end>1555</end>
<start>1510</start>
</programme>
<programme>
<desc>
3/6. Celebratory Food: Recipes include slow roast duck with aromatic crispy skin, and gin and tonic granita. Also in HD. [AD,S]
</desc>
<title>Tom Kerridge's Proper Pub Food</title>
<end>1625</end>
<start>1555</start>
</programme>
<programme>
<desc>
7/23. Tavistock: Paul Martin and the team visit sunny Tavistock where Phillip Serrell and Charlie Ross examine people's heirlooms. Paul takes a look around Endsleigh Gardens, just down the road. [S]
</desc>
<title>Flog It!</title>
<end>1715</end>
<start>1625</start>
</programme>
<programme>
<desc>
Quiz in which contestants try to score as few points as possible by plumbing the depths of their general knowledge to come up with the answers no-one else can think of. Also in HD. [S]
</desc>
<title>Pointless</title>
<end>1800</end>
<start>1715</start>
</programme>
<programme>
<desc>
The latest national and international news stories from the BBC News team, followed by weather. Also in HD. [S]
</desc>
<title>BBC News at Six</title>
<end>1830</end>
<start>1800</start>
</programme>
<programme>
<desc>
The latest news, sport and weather from London. [S]
</desc>
<title>BBC London News</title>
<end>1900</end>
<start>1830</start>
</programme>
<programme>
<desc>
If it's got Britain talking then it will get talked about on The One Show. Presented by Matt Baker and Alex Jones. Also in HD. [S] Then BBC News.
</desc>
<title>The One Show</title>
<end>2000</end>
<start>1900</start>
</programme>
<programme>
<desc>
8/20. School-based drama. Allie convinces Vaughan to send Justin to a boarding school in an attempt to keep him away from Tiffany but the young lovers have plans of their own. Also in HD. [AD,S]
</desc>
<title>Waterloo Road</title>
<end>2100</end>
<start>2000</start>
</programme>
<programme>
<desc>
9/14. Ten Years of Discount Buying: To test their negotiation skills, the candidates must buy nine items which have featured in previous years' tasks at the best possible prices. Also in HD. [S]
</desc>
<title>The Apprentice</title>
<end>2200</end>
<start>2100</start>
</programme>
    </channel>
    </tvguide>

来自BBC早餐团队的最新新闻、体育、商业和天气。同样在HD[s]中,包括每小时25分钟和55分钟的区域新闻。
早餐
0915
0600
13/20.马特·奥尔赖特(Matt Allwright)调查了骗子的活动,揭露了手机、相机和笔记本电脑中使用的假电池。同样在HD中
假英国
1000
0915
马丁·罗伯茨和露西·亚历山大参观了德文郡的一所小屋、伦敦的一套一楼公寓和兰开夏郡的一所房子。他们在拍卖会上了解了各自的价格
家破人亡
1100
1000
10月8日。一部电视连续剧,镜头捕捉到了保险欺诈者。一名被判有罪的毒贩认为头上的一个肿块会给他带来丰厚的赔偿。同样在HD中
声名狼藉
1130
1100
8/10.纪录片《关注英吉利海峡上的生活》。一群来自韦茅斯的生态渔民使用传统捕鱼方法帮助保护英吉利海峡的鱼类资源。也是高清版。[s]
航道巡逻
1215
1130
霍恩卡斯尔
Tim Wonnacott和他的团队在历史悠久的小镇Horncastle寻找便宜货,Tim参观了伯明翰博物馆和美术馆。同样在HD中
讨价还价
1300
1215
英国广播公司新闻组最新的国内和国际新闻报道,随后是天气。同样是高清
BBC新闻一号
1330
1300
来自伦敦的最新新闻、体育和天气
英国广播公司伦敦新闻
1345
1330
受害者
戏剧系列。一次看似直截了当的家访给尼亚姆带来了难以置信的黑暗。这部纪录片的拍摄与霍华德的计划不符。同样在HD中。[广告,S]
医生
1415
1345
8/10.过去的联系:一个生活模特在一堂绘画课开始时被发现被谋杀。同样在HD中。[广告,S]
布莱克神秘博士
1510
1415
苏格兰西部
尼基·查普曼(Nicki Chapman)穿越苏格兰西部,帮助一对热爱动物的夫妇找到他们完美的乡村之家。在那里,尼基尝试着冰壶。同样在HD中
逃往乡下
1555
1510
3/6.庆祝食品:食谱包括香酥皮慢烤鸭,杜松子酒和滋补格兰尼塔酒。同样是HD。[广告,S]
汤姆·克里奇的酒吧正餐
1625
1555
7/23.塔维斯托克:保罗·马丁和他的团队参观了桑尼·塔维斯托克,菲利普·塞雷尔和查理·罗斯在那里检查人们的传家宝。保罗环顾了沿路的恩德斯利花园。[s]
鞭打它!
1715
1625
竞赛中,参赛者通过深入了解自己的常识,得出其他人想不到的答案,从而获得尽可能少的分数。在HD中也是如此
无意义的
1800
1715
英国广播公司新闻组最新的国内和国际新闻报道,随后是天气。同样是高清
BBC新闻六点
1830
1800
来自伦敦的最新新闻、体育和天气
英国广播公司伦敦新闻
1900
1830
如果它让英国人谈论,那么它将在Matt Baker和Alex Jones主持的一个节目中被谈论。同样在HD[s]和BBC新闻中。
唯一的表演
2000
1900
8/20.校园剧。艾莉说服沃恩将贾斯汀送到寄宿学校,试图让他远离蒂芙尼,但这对年轻情侣有自己的计划。同样在HD中。[广告,S]
窝打老道
2100
2000
9/14.十年折扣购买:为了测试他们的谈判技巧,候选人必须以尽可能最好的价格购买前几年任务中的九件物品。同样是HD。[S]
飞黄腾达
2200
2100

编辑:添加到Silverhunter代码中。仍然停留在。单击

如果您的每个函数都在工作,并且每个迭代都使用一个数据项正确传播表行,那么我将尝试以下操作

设置一个隐藏的div来包含您的描述。在css中创建一个名为hidden的类

.hidden {
    display: none;
}
在附加表行中添加隐藏的div,并添加一个我们可以在ID中使用的标识符。我将其称为rowNum。我们使用rowNum来标识我们的描述div。为了让系统知道要显示哪个描述div,我们还将在单击时将rowNum放在要检索的tr数据属性中

$.ajax({
        url: "xml/tvguide.xml" ,
        dataType: "xml" ,
        type: "GET",
        success: function(data) {
            rowNum = 1;
            $(data).find('tvguide channel[id="bbconemonday"] programme').each(function() {

            var title = $(this).find('title').text();
            var desc = $(this).find('desc').text();
            var start = $(this).find('start').text();
            var end = $(this).find('end').text();
            $('<tr data-id="'+rowNum+'" class="showRow"></tr>').html('<td>'+start+'</td><td>'+end+'</td><td title="'+desc+'">'+title+'<div class="hidden" id="desc_'+rowNum+'">'+desc+'</div></td>').appendTo('#chart');
            rowNum++

        });
    });

尝试在上使用
,而不是单击事件处理程序,如下所示

$("table").on('click','.showRow',function(){
descId= $(this).data('id');
$('#desc_'+descId).dialog({
    modal: true,
    width: 500
});

})

你能发布一个更大的xml块吗?一个包含id=“bbconmonday”的更多程序部分的xml块。单击对我没有任何帮助。有什么想法吗?当我取出.hidden CSS类时,数据就在那里。顺便说一句,我非常感谢你的帮助。@yolad as user26409021说:)在这里使用更好。我更新了我的答案。没有。当我点击它时,仍然没有任何结果。我把表名弄错了,非常感谢。
$("#chart").on('click', 'tr.showrow', function(){
    descId= $(this).data('id');
    $('#desc_'+descId).dialog({
        modal: true,
        width: 500
    });

});
$("table").on('click','.showRow',function(){
descId= $(this).data('id');
$('#desc_'+descId).dialog({
    modal: true,
    width: 500
});