Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript CodeIgniter中按钮单击时正则表达式错误的无效标志_Javascript_Php_Codeigniter_Model View Controller_Web - Fatal编程技术网

Javascript CodeIgniter中按钮单击时正则表达式错误的无效标志

Javascript CodeIgniter中按钮单击时正则表达式错误的无效标志,javascript,php,codeigniter,model-view-controller,web,Javascript,Php,Codeigniter,Model View Controller,Web,我有一个使用外部js文件显示测验的视图。当测验完成后,我会在屏幕上添加一些新的html,包括一个新按钮,该按钮被点击后,会将用户发送到我的主控制器的practiceTask函数。但是,当单击它时,我得到错误: Uncaught SyntaxError: Invalid flags supplied to RegExp constructor 'practiceTask' 因为代码在.js文件中,据我所知,我不能使用site\u url或base\u url。这是正确的方法吗 相关JS: $('

我有一个使用外部js文件显示测验的视图。当测验完成后,我会在屏幕上添加一些新的html,包括一个新按钮,该按钮被点击后,会将用户发送到我的主控制器的practiceTask函数。但是,当单击它时,我得到错误:

Uncaught SyntaxError: Invalid flags supplied to RegExp constructor 'practiceTask'
因为代码在.js文件中,据我所知,我不能使用site\u url或base\u url。这是正确的方法吗

相关JS:

$('#imageLocation').attr("src", "");
var html = '<div class="instruction_block"><p class="instruction_text" style="text-align: center; margin-top: 0">You have completed the ' + text + ' test</p><div class="button_placement" style="margin-top: 300px;"><input class="rounded" style="position: absolute; bottom: 0; right: 0; width: 250px;"" type="button" value="Continue to the next task" onClick="/main/practiceTask/3"></div>';
$('#final_message').append(html);
}


任何帮助都将不胜感激

如果您想在JS页面中获取一个值,可以将其放入一个隐藏的输入中,并在页面加载时使用JS进行解析,以便您可以使用它

您可能遇到的问题是onclick

onClick="/main/practiceTask/3"
使用jQuery执行此操作

var html = '<div class="instruction_block"><p class="instruction_text" style="text-align: center; margin-top: 0">You have completed the ' + text + ' test</p><div class="button_placement" style="margin-top: 300px;"><input class="rounded" style="position: absolute; bottom: 0; right: 0; width: 250px;"" type="button" value="Continue to the next task" data-url="/main/practiceTask/3"></div>';
$(document).on('click', '.button_placement input', function(e){
    e.preventDefault(); 
    window.top.location = $(this).data('url');
 });

var html='

您已经完成了完成测试的“+text+”测试。谢谢你简洁明了的回答。谢谢你!没问题,很高兴我能帮忙:)

var html = '<div class="instruction_block"><p class="instruction_text" style="text-align: center; margin-top: 0">You have completed the ' + text + ' test</p><div class="button_placement" style="margin-top: 300px;"><input class="rounded" style="position: absolute; bottom: 0; right: 0; width: 250px;"" type="button" value="Continue to the next task" data-url="/main/practiceTask/3"></div>';
$(document).on('click', '.button_placement input', function(e){
    e.preventDefault(); 
    window.top.location = $(this).data('url');
 });