我已经使用 jQuery 用 XML 数据填充了一个选择元素,这并不难。我现在正试图找到一种方法,在其自己的单独 div 区域中显示分配给该选择元素中特定元素的信息。到目前为止,这是我的代码示例:
$('.selectspeak').live('change', function() {
$("#mainOutput").empty();
$(g_playDOM).find("SPEECH").each(function(){
var speaker = $(".selectspeak").val();
var line = $(this).find("LINE").text();
$("#mainOutput").append("<div class='speakerClass'>" + "Speaker: " + speaker + "<br />" + " <div class='speakerClassLine'>" + "<br />" + "Line: " + line + "</div>");
});
});
上面的代码本质上是用说话者数据填充选择标签,没问题。但是在选择扬声器时,它只显示正常的数据,而不是分配给扬声器的数据。如何确保在选择扬声器时仅显示指定的信息?
我已经尝试破解这个坚果几个小时了,进展甚微,所以朝着正确的方向轻推会很棒!:-)
谢谢!
更新:我添加了一个指向实时项目的链接。只需在左侧选择一个播放,然后您将能够在右侧看到我正在谈论的选择元素。谢谢。
http://scmweb.infj.ulst.ac.uk/~B00351504/COM601/assignment_2/siab.html
第二次更新:
根据要求的一些 XML 行:
<PLAY>
<TITLE>The Merchant of Venice</TITLE>
<FM>
<P>
ASCII text placed in the public domain by Moby Lexical Tools, 1992.
</P>
<P>SGML markup by Jon Bosak, 1992-1994.</P>
<P>XML version by Jon Bosak, 1996-1999.</P>
<P>
The XML markup in this version is Copyright © 1999 Jon Bosak. This work may freely be distributed on condition that it not be modified or altered in any way.
</P>
</FM>
<PERSONAE>
<TITLE>Dramatis Personae</TITLE>
<PERSONA>The DUKE OF VENICE.</PERSONA>
<PGROUP>
<PERSONA>The PRINCE OF MOROCCO</PERSONA>
<PERSONA>The PRINCE OF ARRAGON</PERSONA>
<GRPDESCR>suitors to Portia.</GRPDESCR>
</PGROUP>
<PERSONA>ANTONIO, a merchant of Venice.</PERSONA>
<PERSONA>BASSANIO, his friend, suitor likewise to Portia.</PERSONA>
<PGROUP>
<PERSONA>SALANIO</PERSONA>
<PERSONA>SALARINO</PERSONA>
<PERSONA>GRATIANO</PERSONA>
<PERSONA>SALERIO</PERSONA>
<GRPDESCR>friends to Antonio and Bassanio.</GRPDESCR>
</PGROUP>
<PERSONA>LORENZO, in love with Jessica.</PERSONA>
<PERSONA>SHYLOCK, a rich Jew.</PERSONA>
<PERSONA>TUBAL, a Jew, his friend.</PERSONA>
<PERSONA>LAUNCELOT GOBBO, the clown, servant to SHYLOCK.</PERSONA>
<PERSONA>OLD GOBBO, father to Launcelot.</PERSONA>
<PERSONA>LEONARDO, servant to BASSANIO.</PERSONA>
<PGROUP>
<PERSONA>BALTHASAR</PERSONA>
<PERSONA>STEPHANO</PERSONA>
<GRPDESCR>servants to PORTIA.</GRPDESCR>
</PGROUP>
<PERSONA>PORTIA, a rich heiress.</PERSONA>
<PERSONA>NERISSA, her waiting-maid.</PERSONA>
<PERSONA>JESSICA, daughter to SHYLOCK.</PERSONA>
<PERSONA>
Magnificoes of Venice, Officers of the Court of Justice, Gaoler, Servants to Portia, and other Attendants.
</PERSONA>
</PERSONAE>
<SCNDESCR>
SCENE Partly at Venice, and partly at Belmont, the seat of PORTIA, on the Continent.
</SCNDESCR>
<PLAYSUBT>THE MERCHANT OF VENICE</PLAYSUBT>
<ACT>
<TITLE>ACT I</TITLE>
<SCENE>
<TITLE>SCENE I. Venice. A street.</TITLE>
<STAGEDIR>Enter ANTONIO, SALARINO, and SALANIO</STAGEDIR>
<SPEECH>
<SPEAKER>ANTONIO</SPEAKER>
<LINE>In sooth, I know not why I am so sad:</LINE>
<LINE>It wearies me; you say it wearies you;</LINE>
<LINE>But how I caught it, found it, or came by it,</LINE>
<LINE>What stuff 'tis made of, whereof it is born,</LINE>
<LINE>I am to learn;</LINE>
<LINE>And such a want-wit sadness makes of me,</LINE>
<LINE>That I have much ado to know myself.</LINE>
</SPEECH>