[英]Uncaught SyntaxError: Invalid regular expression flags — what is going on?
I am trying to create rows dynamically that when clicked load a view for the associated row. 我正在尝试动态创建行,当单击该行时为相关行加载视图。 My code (in javascript and jquery) is below
我的代码(在javascript和jquery中)如下
var row = $('<tr />');
var action = '@Url.Action("Get", "myController", new { myID = "__param__" })';
action = action.replace('__param__', rowData.myID)
row.attr('onclick', action);
$("#ListTable > tbody").append(row);
The rows created look like this 创建的行如下所示
<tr onclick="/myControler/Get?myID=113066"><td width="20%">12345</td><td width="80%">Test Text</td></tr>
However, when I click the row, I get the error: 但是,当我单击该行时,出现错误:
Uncaught SyntaxError: Invalid regular expression flags.
I have no clue what I'm doing wrong here, as everything looks good. 我不知道我在做什么错,因为一切看起来都不错。 Any help would be appreciated.
任何帮助,将不胜感激。
You should not be using attr()
to attach an event. 您不应该使用
attr()
附加事件。 What you want to do is make a link when they click? 您想要做的就是单击他们时链接? So you need to set the page location.
因此,您需要设置页面位置。
row.on('click', function () {
window.location.href = action
});
Your onclick
attribute must contain JavaScript. 您的
onclick
属性必须包含JavaScript。 In JavaScript, an expression that starts and ends with slashes, like /myControler/
is a regular expression. 在JavaScript中,以
/myControler/
开头和结尾的表达式是正则表达式,例如/myControler/
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.