簡體   English   中英

從錨標簽調用javascript函數

[英]Call javascript function from anchor tag

我正在從錨標記調用 javascript 函數。 但問題是我正在從代碼渲染塊渲染錨標記。 從這里我從數據庫中獲取一個值並將其作為參數發送到函數。 我的代碼是:

<div>
<%-- <h3> Curent </h3>--%>
<ul>
<%                                
   if (_dsContent.Tables.Count == 0)
      return;
   System.Collections.Generic.List<string> lstCat =
   new System.Collections.Generic.List<string>();

   foreach (System.Data.DataTable table in _dsContent.Tables)
   {
    foreach (System.Data.DataRow row in table.Rows)
    {
     if (String.IsNullOrEmpty(Convert.ToString(row["ContentPart"])))
       {
         if (Convert.ToString(row["Content"]).Length > 200)
           content = Convert.ToString(row["Content"]).Substring(0, 200);
         else
           content = Convert.ToString(row["Content"]);
       }
     else
       {
       if (Convert.ToString(row["ContentPart"]).Length > 200)
        content = Convert.ToString(row["ContentPart"]).Substring(0, 200);
       else
         content = Convert.ToString(row["ContentPart"]);
       }                       

string catStr = Convert.ToString(row["categoryString"]);
string[] arrayCat = new string[2];

if (!String.IsNullOrEmpty(catStr))
{
  arrayCat = catStr.Split(',');
}
if (!String.IsNullOrEmpty(content))
{
  if (!lstCat.Contains(arrayCat[1]))
   {
 Response.Write("<div style='color:Red; font-weight:
 bold;font-size:20px'>" + arrayCat[1] + "</div>");
 lstCat.Add(arrayCat[1]);
 }

 Response.Write("<li>");
 Response.Write("<div style='background-
 color:#DFD48D'>Posted On - " + row["InsertionDate"] + "</div>");

 Response.Write("<div style='font-weight: bold;text-
 align:justify'>'" + row["Header"] + "'</div>");
 Response.Write("<div style='font-size: small'>Date - '" + row["Date"] + "'</div>");
 Response.Write("<div style='text-align:justify'>");
 Response.Write(content);

 string jud = Convert.ToString(row["Content"]);

 Response.Write("");

 Response.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 <a href='#' runat='server' onclick=ShowContent()>");

 Response.Write("Read More...");
 Response.Write("</a>");

 Response.Write("</div>");
 Response.Write("</li></br>");
 }
 }
 }                               
    %>

 </ul>
 </div>

在這里,我無法將字符串 jud 作為參數發送。 我的 javascript 函數是

  <script language="javascript" type="text/javascript">

    function ShowContent(jud) {

        PageMethods.ShowContent(jud,Success, Failure);

    }
    function Success(result) {
        window.open('showcontent.aspx', null,'left=200, top=30, height=550, width= 500, 
         status=no, resizable= yes, scrollbars= yes,toolbar= no,location= no, menubar=
                 no');
    }
    function Failure(error) {
        alert(error);
    }

   </script>

請指導。 謝謝

您的onclick周圍應該有引號。

Response.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  <a href='#' runat='server' onclick='ShowContent()'>");

您必須按照聲明中的說明將參數傳遞給ShowContent函數。

function ShowContent(jud)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM