gpt4 book ai didi

javascript - 正则表达式标志参数无效

转载 作者:行者123 更新时间:2023-12-01 00:36:29 26 4
gpt4 key购买 nike

我想使用 javascript 创建一些弹出窗口。我将表内容(包括 url)从我的 codeigniter Controller 传递到我的 codeigniter View 。

这是我的 Controller 中的代码:

public function ajax_list_dokumen($id){
if($this->session->userdata('logged_in')){
$list = $this->m_agency->GetDataDokumen($id);
$data = array();
$no = $_POST['start'];
foreach ($list as $lists) {
$no++;
$row = array();
$row[] = $lists->id_dokumen_persyaratan;
$row[] = $lists->jenis_dokumen;
$row[] = '<a class="btn btn-primary" onclick="popup('.$lists->path_file.', Dokumen Preview, 800, 600)" ><i class="fa fa-eye"><i/></a>';
$data[] = $row;
}

$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->m_agency->count_all_dokumen($id),
"recordsFiltered" => $this->m_agency->count_filtered_dokumen($id),
"data" => $data,
);
//output to json format
echo json_encode($output);
}
}

这是我的 JavaScript:

function popup(url, title, w, h) {
// Fixes dual-screen position Most browsers Firefox
var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : window.screenX;
var dualScreenTop = window.screenTop != undefined ? window.screenTop : window.screenY;
base_url = "<?php echo base_url();?>";
link = base_url+url;
link = link.replace( /s+/gm, "-", link );
var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;

var left = ((width / 2) - (w / 2)) + dualScreenLeft;
var top = ((height / 2) - (h / 2)) + dualScreenTop;
var newWindow = window.open(link, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);

// Puts focus on the newWindow
if (window.focus) {
newWindow.focus();
}
}

当我单击“查看”按钮时,出现“无效正则表达式标记”错误。

最佳答案

Javascript String.replace 仅需要 2 个参数。像这样更改它:

link = link.replace( /s+/gm, "-");

关于javascript - 正则表达式标志参数无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58093019/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com