读取更新面板中选项的 XML (php jquery)
我找到了一个将鼠标悬停在更新面板上的巧妙解决方案,非常简单。
我想做的是从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$("#" + title)
读为$('#A title')
,这似乎是问题所在$("#" + title)
is read as$('#A title')
, this seems to be the problem