当ID具有使用jQuery的类时显示内容

sir*_*und 11 html xml xslt jquery

我正在尝试创建一系列资源框,这些资源框将作为图像和标题显示在页面上.

带有标题的图像

选择(单击)图像(资源)时,将显示包含资源简要描述的下拉框,以及用于获取更多信息的按钮.

出现更多信息选项

再次单击资源时,它将显示资源的完整描述,以及两个按钮:一个用于删除信息,另一个用于较少信息.

编辑媒体信息

我已经使用XSLT根据用户输入资源时提供的XML为每个资源选择内容.

XSLT:

<div id="newContainer">
<div class="hidden">
<xsl:value-of select="/Properties/Data/Group[@Name='Header']/Datum[@Name='Title']"/>
</div>
    <ul id="initialContent">
        <xsl:for-each select="/Properties/Data/Group[@Name='List Item']">
            <li>
                <xsl:attribute name="class">
                    <xsl:value-of select="Datum[@Name='Title']"/>
                </xsl:attribute>
                <a href="#">                
                        <img>
                            <xsl:attribute name="src">
                                <xsl:value-of select="Datum[@Name='Source']"/>
                            </xsl:attribute>
                            <xsl:attribute name="alt">
                                <xsl:value-of select="Datum[@Name='Alt']"/>
                              </xsl:attribute>                      
                        </img>  
            <xsl:value-of select="Datum[@Name='Title']"/>   
                </a>
            </li>
        </xsl:for-each>
    </ul>
</div>
<div id="briefDescription">
<xsl:if test="@class=Datum[@Name='Title']">
     <xsl:for-each select="/properties/Data/Group[@Name='List Item']">
        <a>         
        <xsl:value-of select="Datum[@Name='Description']"/>
        <xsl:value-of select="normalize-space(substring(title,1,50))" disable-output-escaping="yes"/>
    <xsl:if test="string-length(title) &gt; 50">..</xsl:if>         
        </a>
    </xsl:for-each>
</xsl:if>
</div>
Run Code Online (Sandbox Code Playgroud)

XML:

<Data>
<Datum Exposed="true" ID="ResourceTitle" Name="Title" Type="String">Title</Datum>
<Group Exposed="true" ID="Resource" Name="List Item" Replicatable="true">
<Datum Exposed="true" ID="ResourceName" Name="Name" Type="String">Resource Name</Datum>
<Datum Exposed="true" ID="ResourceSource" Name="Source" Type="File"><![CDATA[$URL_PREFIX/assets/sites/hea1/pages/hea-building.jpg]]></Datum>
<Datum Exposed="true" ID="ResourceLink" Name="Link" Type="File"><![CDATA[Http://www.bbc.co.uk]]></Datum>
<Datum Exposed="true" ID="ResourceAlt" Name="Alt" Type="String">Alt Text</Datum>
<Datum Exposed="true" ID="ResourceDescription" Name="Description" Type="Textarea">Introductory Text</Datum>
</Group>
</Data>
Run Code Online (Sandbox Code Playgroud)

然后我使用jQuery让盒子向下滑动,向上滑动,隐藏等.

在选择资源时,我无法确保XSLT格式化正确的资源信息.

我可以使用jQuery来识别一个类,然后使用XSLT来检查XML节点上的那个类吗?例如:

function getClassName() {

$('li').click(function(){
var chosenClass = $(this).attr('class');
alert(chosenClass);
});

}

<xsl:when test ="$chosenClass and Datum[@Name='Title']">
Run Code Online (Sandbox Code Playgroud)

我为选定的资源提供了一个唯一的ID,并使用XSLT设置由XML节点名称Name提供的var类名.

以下jQuery是我到目前为止所拥有的.在我尝试将类设置为id $('#briefDescription')之前,它会做它应该做的事情.

$(document).ready(function () {
getClassName();
displayContent();
infoMsgRemove();
removeInfo();
moreInfo();
});

var briefInfo = $('#briefDescription');
var moreInfo = $('#moreInfo');
var fullInfo = $('#fullDescription');
var newBriefInfo = newBriefInfo;

function getClassName() {

$('a').click(function () {
    var chosenClass = $(this).attr('class');
    var selectedClass = chosenClass;
    alert(selectedClass + ' chosen');

    briefInfo.addClass(chosenClass);
    var newBriefInfo = briefInfo.addClass(chosenClass);
    var createdBriefInfo = newBriefInfo;
    alert('class added'+ briefInfo.text());
});
}

function displayContent() {

$('#initialContent').click(function (e) {  

    if (newBriefInfo.is(':hidden')) {
        newBriefInfo.slideDown('fast');
        moreInfo.show('li');
    } else {
        fullInfo.slideDown('fast');
        moreInfo.hide('li');
    }
    e.preventDefault();
});
}

function moreInfo() {

$('#moreInfo').click(function () {
    if (fullInfo.is(':hidden')) {
        fullInfo.slideDown('fast');
        moreInfo.hide('li');
    }
});
}

function infoMsgRemove() {

$('#noInfo').click(function () {
    fullInfo.hide();
    briefInfo.hide();
    alert('msg hidden');
});
}

function removeInfo() {

$('#lessInfo').click(function () {
    fullInfo.slideUp('fast');
    moreInfo.show('li');
});
}
Run Code Online (Sandbox Code Playgroud)

创建了一个JSFiddle,希望能够在某种程度上展示我想要做的事情.

在函数getClassName中的警报;

alert('class added'+ briefInfo);
Run Code Online (Sandbox Code Playgroud)

回归'class added [object object]'.

我认为这是因为HTML是由对象的字符串表示填充的?

这是正在进行中的工作.

小智 1

我认为最简单的方法是为“按钮”提供共享类和自定义 ID。然后使用 jQuery 读取单击的按钮类项目的自定义 ID,并对描述的类使用命名策略以使其正确显示。

网页:

<a href="#" class="myResources" id="resource_1">
    <h2>resource 1</h2>
</a>
Run Code Online (Sandbox Code Playgroud)

和 JavaScript/jQuery:

$(".myResources").click(function() {
//And use the same id as class of the description for easy targetting.
var resName = $(this).attr('id');
    $('.'+resName).show();
});
Run Code Online (Sandbox Code Playgroud)

希望这就是我们正在寻找的您。可能不是最干净的解决方案。 HTML5 自定义数据属性可能更适合。