从锚标记调用javascript函数 [英] Call javascript function from anchor tag
本文介绍了从锚标记调用javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从锚标签调用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表 in _dsContent.Tables)
{
foreach(System.Data。 DataRow行在 table.Rows)
{
if ( String .IsNullOrEmpty(Convert.ToString(row [ ContentPart])))
{
if (Convert.ToString(row [ 内容])。长度> 200 )
content = Convert.ToString(row [ 内容])。子串( 0 , 200 );
else
content = Convert.ToString(row [ 内容跨度>]);
}
else
{
if (转换.ToString(row [ ContentPart])。长度> 200 )
content = Convert.ToString(row [ ContentPart])。子串( 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 =颜色:红色; font-weight:< br mode = hold /> bold; font-size:20px > + arrayCat [ 1 ] + < / div>);
lstCat.Add(arrayCat [ 1 ]);
}
Response.Write( < li>);
Response.Write( < div style = background-< br mode = hold /> color:#DFD48D >张贴在 - + row [ InsertionDate] + < / div>);
Response.Write( < div style = font-weight :bold; text-< br mode = hold /> align:justify >' + row [ 标题] + '< / div>跨度>);
Response.Write( < div style = font-size:small >日期 - ' + row [ 日期] + '< / div> 跨度>);
Response.Write( < div style = text-align:justify >);
Response.Write(内容);
string jud = Convert.ToString(row [ Content]) ;
Response.Write( );
Response.Write(
< a href ='#'runat = server önclick= ShowContent()>);
Response.Write( Read More ...);
Response.Write( );
Response.Write( < / div>);
Response.Write( < / li>);
}
}
}
%>
< / string > < / string > < / ul >
< / div >
这里我无法发送字符串判断作为参数。我的javascript函数是
< script language = javascript 类型 = text / javascript >
function ShowContent(jud){
PageMethods.ShowContent(判断,成功,失败);
}
函数成功(结果){
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' 跨度>);
}
函数失败(错误){
alert(error);
}
< / script >
解决方案
你是否在 ready方法中调用你的js函数如下? 。检查。
< script type = text / javascript >
(文件).ready(function(){
//你的代码
});
< / script > 跨度>
I am calling javascript function from anchor tag. But problem is i am rendering anchor tag from code rendering block. From here i am fetching a value from database and sending to the function as a parameter. My code is:
<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:<br mode="hold" /> bold;font-size:20px">" + arrayCat[1] + "</div>");
lstCat.Add(arrayCat[1]);
}
Response.Write("<li>");
Response.Write("<div style="background-<br mode="hold" /> color:#DFD48D">Posted On - " + row["InsertionDate"] + "</div>");
Response.Write("<div style="font-weight: bold;text-<br mode="hold" /> 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" önclick=ShowContent()>");
Response.Write("Read More...");
Response.Write("");
Response.Write("</div>");
Response.Write("</li>");
}
}
}
%>
</string></string></ul>
</div>
here i am not able to send string jud as parameter. my javascript function is
<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>
解决方案
Do you call your js function inside the ready method is as below ? .Check that.
<script type="text/javascript">
(document).ready(function() { //your code }); </script>
这篇关于从锚标记调用javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文