[英]How do I pass database column values as parameters of a JavaScript function?
I have a column in grid which is of hyperlink type and when I click, it should take me URL on basis of JavaScript function. 我在网格中有一个超链接类型的列,当我单击时,它应该基于JavaScript函数带我URL。 Now my question is how should I pass database column name as parameter into JavaScript function.
现在我的问题是如何将数据库列名作为参数传递给JavaScript函数。 I tried something which is not fruitful.
我尝试了一些没有成果的东西。
<ItemTemplate>
<td colname="time_type" >
<a ><%#DataBinder.Eval(Container.DataItem, "TYPE_SEQ")%></a>
</td>
</ItemTemplate>
function Time_type(<%# Eval( "TIME_TYPE_INDICATOR" ) %>,<%# Eval( "TYPE_SEQ" ) %>){
var url;
if (<%# Eval( "INDICATOR" ) %> == 'O'){
url= www.something.com/<%# Eval( "TYPE_SEQ" ) %>?;
}
else if(<%# Eval( "INDICATOR" ) %> == 'T'){
url= www.something.com/<%# Eval( "TYPE_SEQ" ) %>?;
}
}
The function here is taking 2 database columns as parameters and based on one parameter other parameter is used as query string in URL. 这里的功能是以2个数据库列作为参数,并基于一个参数将另一个参数用作URL中的查询字符串。 My javascript function is not working and I know it is not right way to pass paramaters like this.Please help.
我的javascript函数无法正常工作,我知道这不是传递此类参数的正确方法。请提供帮助。 **Also please show me how to call this function on hyperlink click **
**还请向我展示如何在超链接上调用此函数**
I might sound stupid but why use so difficult names for function(someName,someOtherName)... For example doesn't functions work like this: 我听起来可能很愚蠢,但是为什么要对函数使用如此困难的名称(someName,someOtherName)...例如,函数无法像这样工作:
function someFunction(val1,val2){
var troll = val1+val2;
return troll;
}
var temp = someFunction(1,2); // temp is now 3. So here is the right way to call functions and pass it parameters.
I'm still quite new to coding in general but I think from hyperlink it goes like this: 一般而言,我对编码还是很陌生,但我认为从超链接来看,它像这样:
<a onClick='someFunction(someValue,someOtherValue);'></a>
Also I would put in quotes when assigning variable: url = "www.something.com/"+someVariable; 在分配变量时,我也会用引号引起来:url =“ www.something.com/"+someVariable;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.