如何将字符串值作为参数发送到c#中的onclick函数 [英] How send string value as parameter to onclick function in c#
本文介绍了如何将字符串值作为参数发送到c#中的onclick函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Ls是一个链接对象
LS.Attributes.Add( onclick, myPopup5(1234) );
以上代码正常工作,但以下指定的代码无效...
无法发送字符串作为paramenter
LS.Attributes.Add( onclick , myPopup5(ABCD));
解决方案
因为ABCD是一个字符串,因为你没有把它放在引号中,解析器认为它是一个对象,它不是。
尝试
LS.Attributes.Add( onclick, myPopup5('ABCD')) ;
下面没有用,因为JavaScript无法将ABCD识别为对象(考虑到你在这里传递一个简单的字符串)。
将其更改为LS.Attributes.Add(onclick,myPopup5('ABCD'));
[注意单引号]它应该工作细
Ls is a link object
LS.Attributes.Add("onclick", "myPopup5(1234)");
Above code is working but the below specified code not working ..
Not able to send a string as a paramenter
LS.Attributes.Add("onclick", "myPopup5(ABCD)");
解决方案
Because ABCD is a string and since you did not put it in quotes the parser assumes it is an object, which it is not.
Try
LS.Attributes.Add("onclick", "myPopup5('ABCD')");
Below is not working because the JavaScript is not able to recognize ABCD as an object (considering you are passing a simple string here).
Change it toLS.Attributes.Add("onclick", "myPopup5('ABCD')");
[note the single quote] and it should work fine.
这篇关于如何将字符串值作为参数发送到c#中的onclick函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文