将参数传递给函数时出现 Javascript 语法错误
我不确定如何编码,因为我可能会遇到服务器端渲染与客户端渲染的情况。我已经有一段时间没有做过这样的事情了,因此您的意见非常有帮助。
我正在使用模式弹出扩展程序来显示从数据库获取并在网格视图内的标签中呈现的消息。我的想法是使用负责显示模式弹出窗口的 JavaScript 函数。最初的方法是向函数发送两个参数,一个是“this”关键字,另一个是由 .net <%# Eval("Message") %> 呈现的消息本身。然而,这给我带来了各种语法上的麻烦。它应该像 OnClientClick='showComfirm(this, <%# Eval("Message") %>); 一样简单return false;' 但事实并非如此。
然后我想我可以使用document.getElementById(ct100_ContentsPlaceholder1_hEmailMessage).value
。这可行,但不行的是,在弹出窗口中分配标签的值。这里有一些代码:
function displayInfo(source, message){
this._source = source;
var emailBody = document.getElementById("ct100_ContentsPlaceholder1_hEmailMessage).value;
document.getElementById("ct100_ContentsPlaceholder1_lblPopUpMessage").value = emailBody; // This is where I'm trying to assing text property.
this._popup - $find('mdlPopup');
this._popup.show();
}
“message”参数是我在顶部描述的初始方法,我仍然想让它起作用。
无论如何,有很多解释,但希望您输入有关为什么我在初次尝试中遇到语法错误的信息,以及为什么我无法将值分配给 lblPopUpMessage 的文本属性。
谢谢, Risho
更新
我收到的 javascript 错误是由于变量“message”包含的文本造成的。变量包含纯英文文本,例如电子邮件消息,包含大写、小写字母、感叹号、逗号、句号、撇号、双引号、空格等。我如何知道这一点?我已删除所有文本,仅在数据库的消息单元格中保存一个随机单词,并且错误消失了。但仍然无法显示单个工作消息。
那么有解决方法吗?
谢谢,R。
I'm not sure how to code this as I may be running into the server side rendering versus client side. It's been a while since I did something like this therefore your input is very helpful.
I'm using a modal popup extender to display a message that is fetched from a database and is rendered in label inside a gridview. My ideas was to use the JavaScript function that is responsible for showing the modal popup. Initial method was to send two params to the function, one being the "this" keyword and the other the message itself as rendered by the .net <%# Eval("Message") %>. This however gave me all kind of syntactical trouble. It should have been as simple as OnClientClick='showComfirm(this, <%# Eval("Message") %>); return false;'
but wasn't.
Then I thought I can just use the document.getElementById(ct100_ContentsPlaceholder1_hEmailMessage).value
. This works but what doesn't is, assigning the value of the label in the popup. Here some code:
function displayInfo(source, message){
this._source = source;
var emailBody = document.getElementById("ct100_ContentsPlaceholder1_hEmailMessage).value;
document.getElementById("ct100_ContentsPlaceholder1_lblPopUpMessage").value = emailBody; // This is where I'm trying to assing text property.
this._popup - $find('mdlPopup');
this._popup.show();
}
The "message" parameter is what I described at the top as my initial method, which I still would like to make it work.
Anyway, lot of explanation, but would like your input as to why I get syntax error in my initial attempt, as well as why am I not able to assign the value to the text property of the lblPopUpMessage.
Thanks,
Risho
UPDATE
The javascript errors I was getting were due to the text which the varialble "message" contains. The varialbe contains plain English text such as a email message, with upper case, lower case letters, exclamation marks, commas, periods, appostrophies, double quotes, space, etc. How do I know this? I've removed all the text save one random word in the message cell in the database and the errors went away. Still could not display the single workd message though.
So is there a workaround for this?
Thanks, R.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您复制+粘贴代码吗?如果是这样,则出现语法错误。这是好的代码:
You copy + paste the code ? If so, you got a syntax error. This is the good code: