将ListView元素获取到JavaScript数组中 [英] Get ListView elements into JavaScript Array
本文介绍了将ListView元素获取到JavaScript数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果有人可以帮助我,请在这里发帖,请给我指点。我相信它更容易发布链接,而不是再次重写整个线程。谢谢。
http://forums.asp.net/t/1906515.aspx/1?Getting+ListView+ul+li+asp+label+values+进入+ a + javascript +数组
If anyone can help me, have a post here, please give me some direction. I believe its easier to just post the link, than to rewrite to whole thread again. Thanks.
http://forums.asp.net/t/1906515.aspx/1?Getting+ListView+ul+li+asp+label+values+into+a+javascript+array
推荐答案
谢谢谢谢,我有解决方案!非常感谢您的所有意见,并推动我开发解决方案。这段代码可能会缩短一点,但它正在运行。我最终将更改为a,这使得使用
类名以及我分配给标签的类名更容易遍历DOM。我发现的一件事是,如果标签Visible属性设置为false,(某些值我不想向用户显示).Net将不会在浏览器中呈现它。所以,为了解决这个问题,我将标签Visible属性设置为true,然后我将jss设置为display:none;这很好用。这是原始HTML和脚本。非常感谢谢谢谢谢!
Hi Sergey, I have the solution! Thank you very much for all of your input, and for pushing me to develop the solution. This code could probably be shortened a bit, but it is working. I ended up changing theto a , which made it easier to traverse the DOM using the
classname, and the class names that I assigned to my labels. One thing that I found out was, if a labels "Visible" property is set to false,(some values I did not want to show the user) .Net will not render it in the browser. So, to get around this, I set the labels Visible property to "true", and I juse set the Css to display:none; This worked good. Here is the original HTML, and the scripts. Thank you very much for the links Sergey!
<!-- DataList holds locations returned from DB --> <asp:datalist id="healthCenters" cssclass="hcListing" runat="server" xmlns:asp="#unknown"> EnableViewState="False" DataKeyField="LocationID"> <itemtemplate> <table class="locations" border="0"> <tr class="details"> <td class="locationDetails"><asp:hyperlink cssclass="hcName" id="hlCenterName" runat="server" text="<%# Eval("CenterName") %>" navigateurl="<%# Eval("LocationID", "searchResponse.aspx?LocationID={0}") %>"></asp:hyperlink><br /> Address: <asp:label cssclass="address" id="lblAddress" runat="server"> Text='<%# Eval("Address") %>' /><br /> City/State: <asp:label cssclass="city" id="lblCity" runat="server" text="<%# Eval("City") %>" /> , <asp:label cssclass="state" id="lblState" runat="server" text="<%# Eval("State") %>" /><br /> Zip: <asp:label cssclass="zip" id="lblZipCode" runat="server"> Text='<%# Eval("ZipCode") %>' /><br /> Phone: <asp:label cssclass="phone" id="lblPhoneNumber" runat="server"> Text='<%# String.Format("{0:(###) ###-####}",Convert.ToInt64(Eval("PhoneNumber"))) %>' /><br /> Web: <asp:hyperlink cssclass="url" id="webSite" runat="server" navigateurl="<%# Eval("Website") %>"> Text='<%# Eval("Website") %>'>HyperLink</asp:hyperlink><br /> Patient Services:<asp:label cssclass="services" id="lblPatientServices" runat="server"> Text='<%# Eval("PatientServices") %>' /><br /> Distance: <asp:label cssclass="distance" id="lblRadius" runat="server" visible="True"> Text='<%# String.Format("{0:0.##}", Eval("DistanceMiles")) + " " + "miles." %>' /><br /> <asp:label cssclass="locationId" id="lblLocationID" runat="server" visible="true"> Text='<%# Eval("LocationID") %>' /><br /> <asp:label cssclass="lat" id="lblLat" runat="server" visible="true" text="<%# Eval("Lat") %>" /><asp:label cssclass="lng" id="lblLng" runat="server" visible="true" text="<%# Eval("Long") %>" /> <br /> </asp:label></asp:label></asp:label></asp:label></asp:label></asp:label></td> </tr> </table> </itemtemplate> </asp:datalist>
// javascript
//the javascript
function AddData() { var locationAry = []; //Use the jQuery .each() function to get each item
( td.locationDetails)。each(function(i,elem) ){
var liListContent = {};
liListContent.centerName =("td.locationDetails").each(function (i, elem) { var liListContent = {}; liListContent.centerName =
( this )。find( 。hcName)。html ();
liListContent.centeraddress =(this).find(".hcName").html(); liListContent.centeraddress =
这篇关于将ListView元素获取到JavaScript数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文登录 关闭
扫码关注1秒登录发送“验证码”获取 | 15天全站免登陆