读取更新面板中选项的 XML (php jquery)

发布于 2024-10-01 18:47:21 字数 4056 浏览 4 评论 0原文

我找到了一个将鼠标悬停在更新面板上的巧妙解决方案,非常简单。

我想做的是从 xml 中读取“选项”,而不是像这个例子一样的静态字符串:

    $(document).ready(function(){
                    var options = {'solutions':"<h1 class='middleh1'>Solving Your Tech Problems.</h1><p>Below are a couple of areas that Felecan specializes in:<ul><li>Web Application Development</li><li>Search Engine Marketing</li><ul>",'passion':"<h1 class='middleh1'>Welcome To Felecan!</h1><p>Felecan believes in helping companies and individuals realize their full potential on the Internet with top of the line tools and support. This means fast response times, and help for your technology problems right away.</p>",'technology':"<h1 class='middleh1'>Technology Done Right.</h1><p>From PHP to Python, the Django framework, and jQuery for JavaScript/Ajax your ideas can become professional products for less than you thought!"}
                    var array = ['solutions','technology','passion'];
                    random =Math.floor(Math.random()*2)
                    $("#doc_box_right").html(options['passion']);
                    $("#solutions").css("cursor","pointer");
                    $("#technology").css("cursor","pointer");
                    $("#passion").css("cursor","pointer");
                    $("#solutions").mouseover(function() {
                        $("#doc_box_right").html(options.solutions);
                    });
                    $("#passion").mouseover(function() {
                        $("#doc_box_right").html(options.passion);
                    });
                    $("#technology").mouseover(function() {
                        $("#doc_box_right").html(options.technology);
                    });
                });

<div id="doc_box_left">
                    <ul style="list-style-image: url(http://www.felecan.com/media/images/arrow.png);">
                        <li id="passion">Passion</li>
                        <li id="solutions">Solutions</li>
                        <li id="technology">Technology</li>
                    </ul>
                </div>
                <div id="doc_box_right">
                </div>

我需要从我拥有的 xml 文档中创建选项、光标指针和鼠标悬停效果。 xml 文档的节点具有两个属性:

<statements>
<statement title="A Title" statement="The statement"/>
<statement title="Another Title" statement="The statement for this"/>
</statements>

标题将是列表项,语句将是 html 'doc_box_right' 工作解决方案中的更新

<script type="text/javascript">
    $(document).ready(function () {
        $.ajax({
            type: "GET",
            url: "php/docstatement_genxml.php",
            dataType: "xml",
            success: parseXml
        });
    });
    function parseXml(xml) {
        var items = [];
        $(xml).find("statement").each(function () {
            var title = $(this).attr("title");
            var titleid = (title.substr(0, 8)).replace(" ", "_");
            items.push('<li id="' + titleid + '">' + title + '</li>');
        });
        $('#doclist').append(items.join(''));
        $(xml).find("statement").each(function () {
            var title = $(this).attr("title");
            var titleid = (title.substr(0, 8)).replace(" ", "_");
            var id = '#' + titleid;
            var statement = $(this).attr("text");
            $(id).css("cursor", "pointer");
            $(id).mouseover(function () {
                $("#doc_box_right").html('<h2>' + title + '</h2><p>' + statement + '</p>');
            });
        });

    }
</script>

            <div id="doctrine_box">
                <div id="doc_box_left">
                    <ul id="doclist">
                    </ul>
                </div>
                <div id="doc_box_right">
                </div>
            </div>

I found a neat solution for mouse over update panel, real simple.

What I'd like to do is read the 'options' from xml instead of static string like this example:

    $(document).ready(function(){
                    var options = {'solutions':"<h1 class='middleh1'>Solving Your Tech Problems.</h1><p>Below are a couple of areas that Felecan specializes in:<ul><li>Web Application Development</li><li>Search Engine Marketing</li><ul>",'passion':"<h1 class='middleh1'>Welcome To Felecan!</h1><p>Felecan believes in helping companies and individuals realize their full potential on the Internet with top of the line tools and support. This means fast response times, and help for your technology problems right away.</p>",'technology':"<h1 class='middleh1'>Technology Done Right.</h1><p>From PHP to Python, the Django framework, and jQuery for JavaScript/Ajax your ideas can become professional products for less than you thought!"}
                    var array = ['solutions','technology','passion'];
                    random =Math.floor(Math.random()*2)
                    $("#doc_box_right").html(options['passion']);
                    $("#solutions").css("cursor","pointer");
                    $("#technology").css("cursor","pointer");
                    $("#passion").css("cursor","pointer");
                    $("#solutions").mouseover(function() {
                        $("#doc_box_right").html(options.solutions);
                    });
                    $("#passion").mouseover(function() {
                        $("#doc_box_right").html(options.passion);
                    });
                    $("#technology").mouseover(function() {
                        $("#doc_box_right").html(options.technology);
                    });
                });

<div id="doc_box_left">
                    <ul style="list-style-image: url(http://www.felecan.com/media/images/arrow.png);">
                        <li id="passion">Passion</li>
                        <li id="solutions">Solutions</li>
                        <li id="technology">Technology</li>
                    </ul>
                </div>
                <div id="doc_box_right">
                </div>

I need to create the options, cursor pointers, and mouseover effects all from an xml doc I have. The xml doc has nodes with two attributes:

<statements>
<statement title="A Title" statement="The statement"/>
<statement title="Another Title" statement="The statement for this"/>
</statements>

the title would be the list items, the statement would be the update in the html 'doc_box_right'

WORKING solution:

<script type="text/javascript">
    $(document).ready(function () {
        $.ajax({
            type: "GET",
            url: "php/docstatement_genxml.php",
            dataType: "xml",
            success: parseXml
        });
    });
    function parseXml(xml) {
        var items = [];
        $(xml).find("statement").each(function () {
            var title = $(this).attr("title");
            var titleid = (title.substr(0, 8)).replace(" ", "_");
            items.push('<li id="' + titleid + '">' + title + '</li>');
        });
        $('#doclist').append(items.join(''));
        $(xml).find("statement").each(function () {
            var title = $(this).attr("title");
            var titleid = (title.substr(0, 8)).replace(" ", "_");
            var id = '#' + titleid;
            var statement = $(this).attr("text");
            $(id).css("cursor", "pointer");
            $(id).mouseover(function () {
                $("#doc_box_right").html('<h2>' + title + '</h2><p>' + statement + '</p>');
            });
        });

    }
</script>

            <div id="doctrine_box">
                <div id="doc_box_left">
                    <ul id="doclist">
                    </ul>
                </div>
                <div id="doc_box_right">
                </div>
            </div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

画中仙 2024-10-08 18:47:21
<statements>
<statement title="A Title" statement="The statement" id="title_a"/>
<statement title="Another Title" statement="The statement for this" id="title_b"/>
</statements>

var xml_id = $(this).attr("id");
$("#" + xml_id).css("cursor", "pointer");

$("#" + title) 读为 $('#A title'),这似乎是问题所在

<statements>
<statement title="A Title" statement="The statement" id="title_a"/>
<statement title="Another Title" statement="The statement for this" id="title_b"/>
</statements>

var xml_id = $(this).attr("id");
$("#" + xml_id).css("cursor", "pointer");

$("#" + title) is read as $('#A title'), this seems to be the problem

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文