ds2128629 2017-02-25 04:46
浏览 31
已采纳

编写简单的javascript函数并调用它

I have bootstrap on my site and I want to use a different alertbox when I communicate with the users....

I only use this one: http://bootboxjs.com/documentation.html#bb-alert-dialog

It is defined like this (I always use the large one, and always title "rsite") and I only change the message. I have tried to write a funcion that takes userMessage as argument and outputs this but with no luck. Can you see what I do wrong?

 ReClamVersion = "0.4";

 DEFINE
 bootbox.alert({ 
 size: "large",
 title: ReClamversion,
 message: "Your message here…", 
 })

 My non working function
 function rAlert(userMessage)
 {
 return "bootbox.alert({ message:'" + userMessage + "',size: 'large',¨title:" + ReClamVersion+ '});'
 ;}

I try to invoke it by rAlert("hi") but it doesnt work. Where should I put my script so I can use it on all my pages? I use php and include my header.php. Should I put the script there?

  • 写回答

1条回答 默认 最新

  • dsjq62428 2017-02-25 04:59
    关注

    You don't need quotes if you just want display the alert, using variables as parameters. Moreover the way you put the quotes is incorrect. Try rewriting the function as follows

    function rAlert(userMessage)
     {
     bootbox.alert({ message: userMessage ,size: 'large', title:  ReClamVersion });
     }
    

    It's ok to put the function in the header.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我的数据无法存进链表里
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端