Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.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 如何将参数传递给bootstrap的popover内容函数_Javascript_Twitter Bootstrap - Fatal编程技术网

Javascript 如何将参数传递给bootstrap的popover内容函数

Javascript 如何将参数传递给bootstrap的popover内容函数,javascript,twitter-bootstrap,Javascript,Twitter Bootstrap,我想添加一些条件,比如在弹出框中应该显示什么类型的文本。 所以我写了这个函数: var initErrorPopOverEvent = function(hasRequiredError,option){ if(hasRequiredError !== undefined && hasRequiredError === true){ $(".icon-warning-lg").popover({

我想添加一些条件,比如在弹出框中应该显示什么类型的文本。 所以我写了这个函数:

var initErrorPopOverEvent = function(hasRequiredError,option){
         if(hasRequiredError !== undefined && hasRequiredError === true){
             $(".icon-warning-lg").popover({
                 html:true,
                 placement:'top',
                'trigger': 'hover ',
                 content:function(){
                     return $("#required-field-error").text();
                 }
             });
         }
         if(option !== undefined){
             if(option === "option1"||option === "option2"){
                 $("#opt1-warning").popover({
                     html:true,
                     placement:'top',
                    'trigger': 'hover ',
                     content:function(){
                         return $("#opt1-error").text();
                     }
                 });
             }
             if(option === "option3" || option === "option2"){
                 $("#opt2-warning").popover({
                     html:true,
                     placement:'top',
                    'trigger': 'hover ',
                     content:function(){
                         return $("#opt2-error").text();
                     }
                 });
             }
         }
     }
但我希望所有这些条件都进入显示popover内容的函数内部。 比如:

content:function(hasRequiredError,option){//render text according to condition
}

我该怎么做?

您应该用Javascript向它传递一个映射。{key:value}

试试这个:

var hasRequiredError = ...;
var option = ...;
var options = {'content':initErrorPopOverEvent(hasRequiredError,option)};

$('#myElement').popover( options );