简体   繁体   English

从列表视图布局模板将值传递给javascript

[英]Pass Value to javascript from listview layout template

Want to pass listview item value to javascript function ,this control is inside layout template ie anchor tag .I am binding data to this anchor tag and want to call the javascripot function on this click. 想要将listview项目值传递给javascript函数,此控件位于布局模板(即锚标记)内。我将数据绑定到此锚标记,并希望在此单击时调用javascripot函数。

<asp:ListView ID="ListviewInnerComent" runat="server" DataKeyNames="ID"                                                               OnItemDataBound="ListviewInnerComent_ItemDataBound" OnItemCommand="ListviewInnerComent_ItemCommand">
    <LayoutTemplate>

     <ul id="itemPlaceholderContainer"runat="server">
       <li  id="itemPlaceholder" runat="server">

         </li></ul>

<div >
 <a href='<%# Eval("ID") %>' id="showmore"  class="showmore"  runat="server" onclick="GetRecords1();" >Show More</a>

//WANT TO PASS THIS ANCHOR TAG VALUE  THAT i AM BINDING TO JAVASCRIPT FINCTION. 
                                                                                 </div>


                                                                    </LayoutTemplate>


function GetRecords1
(response) {
        var xmlDoc = $.parseXML(response.d);
        var xml = $(xmlDoc);

    var ID=document.getElementById("showmore").title; 
alert(ID);
WANT TO CALL PASSED VALUE HERE
}

Try using this instead: 尝试使用此代替:

<a href="#" class="showmore"
  onclick="GetRecords1('<%# Eval("ID") %>');return false;">Show More</a>

The href="#" ensures some browsers like IE will handle the element as a link. href =“#”确保某些浏览器(如IE)会将元素作为链接处理。 The return false; 返回false; prevents the web browser following the link after the js function is run. 阻止js函数运行后,Web浏览器跟随链接。

I've removed the id and runat attributes since these aren't required -- this doesn't need to be a server control. 我删除了idrunat属性,因为它们不是必需的-不需要是服务器控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM