javascript - 我的 id 值在传递到其他 Blade 后未从第一个数字读取数字 0

标签 javascript php jquery laravel

我尝试将 id 值传递给我的另一个 Blade ,它起作用了,但另一个 Blade 文件在第一个数字处没有读取 0 的数字。例如,当我传递值 006 时,当我从另一个 Blade View 控制台记录该值时,它只显示 6。

我的 onclick 值已传递

<a class="btn btn-sm btn-default pull-right" type="button" title="Search Branch" onclick="openNewWindow('{{ route('reporting.branchCheckBoxList', ['cuid' => '_cuid_', 'stid' => '_stid_']) }}'.replace('_cuid_', document.getElementById('cu').value).replace('_stid_', document.getElementById('state').value))" ><i class="fa fa-hand-o-up">

网络路由

Route::get('reporting/branchCheckBoxList/{cuid}/{stid?}','GenReportController@branchCheckBoxList')->name('reporting.branchCheckBoxList');

我的 Controller


    public function branchCheckBoxList($cuid, $stid ) {

    $cuid = $cuid;
    $stid = $stid;

    return view('report.BranchCheckBoxList',  compact('cuid','stid'));
}

我的其他 Blade View

<script>
var cuid = {{ $cuid }} ;
console.log(cuid); //my console only read 6 if i pass 006 
</script>

我需要修复我的值,该值可以在第一个数字处返回读取数字0,抱歉我的英语不好

最佳答案

您的代码没有显示前导零,当您使用 laravel dd 函数时,输出为 006 但 console.log 函数会删除前导零。

如果您希望显示前导零,则必须将其格式化为字符串。

<script>
    var cuid = "{{$cuid}}";
    console.log(cuid);
</script>

关于javascript - 我的 id 值在传递到其他 Blade 后未从第一个数字读取数字 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60070540/

相关文章:

javascript - 使用 Javascript 或 jquery 正则表达式验证一个字符串是否包含另一个字符串

javascript - 如何在调整大小时保持两个表的列宽同步?

javascript - 如何从同一个类的div中获取文本值,并显示在另一个div中?

php - 将随机值作为 session "key"存储在表中是否安全?

php - SQL - 将多个行值插入到单个列中

javascript - 如何防止自定义光标移动字母?

jquery - 导航按钮水平循环功能

javascript - 使用 ui-dialog-background 透明对话框更改背景颜色

php - 查找版本号是否在指定范围内

javascript - 如果屏幕宽度小于 960 像素,则将屏幕宽度添加到类中