我从锚标签调用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("
<a href='#' runat='server' onclick=ShowContent()>");
Response.Write("Read More...");
Response.Write("</a>");
Response.Write("</div>");
Response.Write("</li></br>");
}
}
}
%>
</ul>
</div>
这里我无法发送字符串判断作为参数。 我的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>
请指教。 感谢
答案 0 :(得分:0)
onclick
附近应该有引号。
Response.Write("
<a href='#' runat='server' onclick='ShowContent()'>");
您必须按照声明中的说明将参数传递给ShowContent
函数。
function ShowContent(jud)