与 XML JQuery HTML 相关
我是 JQuery 的新手。但是,我正在尝试使用它来做到这一点。 我有一个如下所示的 XML 集:
<?xml version="1.0" encoding="utf-8" ?>
<Columns>
<Column>
<Id>Col_Id_1</Id>
<Name>Col_Name_1</Name>
<Type>int</Type>
</Column>
<Column>
<Id>Col_Id_2</Id>
<Name>Col_Name_2</Name>
<Type>string</Type>
</Column>
<Column>
<Id>Col_Id_3</Id>
<Name>Col_Name_3</Name>
<Type>DateTime</Type>
</Column>
</Columns>
现在,我想做的是:
<div id="header" class="all_are_H3_from_CSS">
<label id="Col_Id_1">Col_Name_2</label> |
<label id="Col_Id_1">Col_Name_3</label> |
<label id="Col_Id_1">Col_Name_4</label> |
</div>
我已经尝试过这种方式:
<script type="text/javascript" language="javascript">
$(document).ready(function(){
$.ajax({
type: "GET",
url: "GetColumnNames.xml",
dataType: "xml",
success: function(xml) {
$(xml).find('Column').each(function(){
var id = $(this).attr('Id');
var title = $(this).find('Name').text();
$('<div class="items" id="link_'+id+'"></div>').html('<label id='+id+'>'+title+'</label>').appendTo('#page-wrap');
});
}
});
});
</script>
但没有得到所需的 o/p。
我怎样才能使用 jquery 来做到这一点? 上面的XML可以是动态的&以字符串格式提供/可以位于 File1.xml
谢谢!
I'm new to JQuery.But, I am trying to do this using it.
I have an XML set that looks like the following:
<?xml version="1.0" encoding="utf-8" ?>
<Columns>
<Column>
<Id>Col_Id_1</Id>
<Name>Col_Name_1</Name>
<Type>int</Type>
</Column>
<Column>
<Id>Col_Id_2</Id>
<Name>Col_Name_2</Name>
<Type>string</Type>
</Column>
<Column>
<Id>Col_Id_3</Id>
<Name>Col_Name_3</Name>
<Type>DateTime</Type>
</Column>
</Columns>
Now, what i want to do is this :
<div id="header" class="all_are_H3_from_CSS">
<label id="Col_Id_1">Col_Name_2</label> |
<label id="Col_Id_1">Col_Name_3</label> |
<label id="Col_Id_1">Col_Name_4</label> |
</div>
I have tried this way :
<script type="text/javascript" language="javascript">
$(document).ready(function(){
$.ajax({
type: "GET",
url: "GetColumnNames.xml",
dataType: "xml",
success: function(xml) {
$(xml).find('Column').each(function(){
var id = $(this).attr('Id');
var title = $(this).find('Name').text();
$('<div class="items" id="link_'+id+'"></div>').html('<label id='+id+'>'+title+'</label>').appendTo('#page-wrap');
});
}
});
});
</script>
but not getting desired o/p.
how can i do this using jquery.
The above XML can be dynamic & is available in string format/can be located at File1.xml
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种选择是使用 XSLT 将其转换为您拥有的 XML/div 表单,然后使用
.load()
jQuery 调用将其插入到您需要的位置发送该客户端。One option would be to use XSLT to transform it to the XML/div form you have, then send that client side using a
.load()
jQuery call inserting it where you need.