简体   繁体   English

如何将数据库列值作为JavaScript函数的参数传递?

[英]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.

相关问题 如何将控制器和动作参数传递给 Rails 3 中的 javascript 函数? - How do I pass the controller and action parameters to a javascript function in Rails 3? 如何通过sprintf()将PHP参数传递给javascript函数? - How do I pass PHP parameters through an sprintf() to a javascript function? 如何将Django的字符串参数传递给javascript函数? - How do I pass string parameters from django to javascript function? 如何将值从grails传递回javascript函数? - How do I pass values from grails back to a javascript function? 如何在Javascript + Node中传递参数? - How do I pass parameters in Javascript + Node? 如何将返回值从javascript函数传递给android? - How do I pass return values from a javascript function to android? 如何在javascript中将值作为参数传递 - How to pass values as parameters in javascript 我需要将空参数传递给 javascript 函数吗? - Do I need to pass empty parameters to a javascript function? 如何将值传递给javascript函数的参数并获得结果 - How to pass values to the parameters of the function of a javascript and get the result 如何从具有串联 html+object 值的变量传递 function 参数? - How do I pass function parameters from a variable with concatenated html+object values?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM