如何使用jQuery解析XML并将内容插入HTML表单?
我有一个带有图像标记的简单XMl文件: XML:如何使用jQuery解析XML并将内容插入HTML表单?,jquery,html,xml,insert,parsing,Jquery,Html,Xml,Insert,Parsing,我有一个带有图像标记的简单XMl文件: XML: 我需要在HTML表单中的标记中插入此内容(“src”attrib) HTML: 有人知道如何使用jQuery实现这一点吗 提前谢谢 H.像这样的东西怎么样: <script type="text/javascript"> function imageData() { //first we need to load the XML data for that detail row //if the functio
我需要在HTML表单中的
标记中插入此内容(“src”attrib)
HTML:
有人知道如何使用jQuery实现这一点吗
提前谢谢
H.像这样的东西怎么样:
<script type="text/javascript">
function imageData() {
//first we need to load the XML data for that detail row
//if the function is a success it will call the function called processDetail
$.ajax({
type: "GET",
url: "PATH_TO_XML_GOES_HERE",
dataType: "xml",
success: getImages
});
}
function getImages(xml) {
//this function gets the results from the xml file
//and inserts them in to the boxes
$(xml).find("img").each(function() {
$("#photos").append(this);
});
}
</script>
函数imageData(){
//首先,我们需要加载该细节行的XML数据
//如果函数成功,它将调用名为processDetail的函数
$.ajax({
键入:“获取”,
url:“指向XML的路径在这里”,
数据类型:“xml”,
成功:getImages
});
}
函数getImages(xml){
//此函数从xml文件获取结果
//并将其插入到框中
$(xml).find(“img”).each(函数(){
$(“#照片”)。附加(本);
});
}
黑名单如下:
可能不起作用,但看起来它会让你走上正轨。像这样的东西怎么样:
<script type="text/javascript">
function imageData() {
//first we need to load the XML data for that detail row
//if the function is a success it will call the function called processDetail
$.ajax({
type: "GET",
url: "PATH_TO_XML_GOES_HERE",
dataType: "xml",
success: getImages
});
}
function getImages(xml) {
//this function gets the results from the xml file
//and inserts them in to the boxes
$(xml).find("img").each(function() {
$("#photos").append(this);
});
}
</script>
函数imageData(){
//首先,我们需要加载该细节行的XML数据
//如果函数成功,它将调用名为processDetail的函数
$.ajax({
键入:“获取”,
url:“指向XML的路径在这里”,
数据类型:“xml”,
成功:getImages
});
}
函数getImages(xml){
//此函数从xml文件获取结果
//并将其插入到框中
$(xml).find(“img”).each(函数(){
$(“#照片”)。附加(本);
});
}
黑名单如下:
可能不起作用,但看起来它会让您上路。既然您的xml文件包含有效的html标记,为什么不直接将其插入到div中呢
$('#photos').load('TheFile.xml')
既然xml文件包含有效的html标记,为什么不直接将其插入到div中呢
$('#photos').load('TheFile.xml')
为什么要将其存储在xml文件中?它只是html。为什么要将它存储在xml文件中?它只是html.Short和sweet,但假设XML文件只包含img标记。如果它实际上包含一个完整的XML文档,那么@easement发布的解决方案将是更好的。简短而甜蜜,但假设XML文件只包含img标记。如果它实际上包含一个完整的XML文档,那么@easement发布的解决方案将更可取。