Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.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 通过数组中的函数引导模式绑定按钮操作_Javascript_Jquery_Arrays_Twitter Bootstrap_Modal Dialog - Fatal编程技术网

Javascript 通过数组中的函数引导模式绑定按钮操作

Javascript 通过数组中的函数引导模式绑定按钮操作,javascript,jquery,arrays,twitter-bootstrap,modal-dialog,Javascript,Jquery,Arrays,Twitter Bootstrap,Modal Dialog,下面的函数使用Bootstrap和JQuery显示一个模式。为了使它更灵活,我想添加尽可能多的按钮,并在按下这些按钮时绑定函数 blnShowWindow("This is <b>html</b> content", "This is a title", [ {strTitle: 'CCancel', strStyle: 'default', fncAction: function() { alert("ccccc"); } }, {strTitle: 'OOK', st

下面的函数使用Bootstrap和JQuery显示一个模式。为了使它更灵活,我想添加尽可能多的按钮,并在按下这些按钮时绑定函数

blnShowWindow("This is <b>html</b> content", "This is a title", [
{strTitle: 'CCancel', strStyle: 'default', fncAction: function() { alert("ccccc"); } },
{strTitle: 'OOK', strStyle: 'primary', fncAction: function() { alert("ok"); } }]);
blnShowWindow(“这是html内容”,“这是标题”[
{strTitle:'CCancel',strStyle:'default',fncAction:function(){alert(“ccccc”);},
{strTitle:'OOK',strStyle:'primary',fncAction:function(){alert(“ok”);}}});
在另一个地方:

intButtonC = 0;
blnShowWindow = function (htmlContent, strTitle, arrButtons) {
  //....
  $.each(arrButtons, function (intIndex, arrButton) {
    intButtonC += 1;
    strButtonID = "btnModalButton" + intButtonC;
    $("#divModalFooter").html($("#divModalFooter").html() + 
      '<button type="button" class="btn btn-'+arrButton.strStyle+
      '" id="'+strButtonID+'">'+arrButton.strTitle+'</button>');
    $("#"+strButtonID).unbind().bind("click",arrButton.fncAction);
  });
  $("#divModal").modal();
};
intButtonC=0;
blnShowWindow=函数(htmlContent、Strttle、arrButtons){
//....
$。每个(arrButtons,函数(intIndex,arrButton){
intButtonC+=1;
strButtonID=“btnModalButton”+intButtonC;
$(“#divModalFooter”).html($(“#divModalFooter”).html()+
''+arrButton.strTitle+'';
$(“#”+strButtonID).unbind().bind(“单击”,arrButton.fncAction);
});
$(“#divModal”).modal();
};
CCancel和OOK两个按钮都显示良好。单击OOK时,将正确显示一个带有“ok”的警报框。问题是,CCancel在单击时不会执行任何操作。数组定义是否正确?我做错了什么


还有更好的方法来定义高度灵活的引导模式吗?

问题是您正在覆盖已绑定的按钮,行中

 $("#divModalFooter").html($("#divModalFooter").html() + ...
例如,如果您尝试此操作,代码将正常工作

intButtonC = 0;
blnShowWindow = function (htmlContent, strTitle, arrButtons) {
  $.each(arrButtons, function (intIndex, arrButton) {
    intButtonC += 1;
    strButtonID = "btnModalButton" + intButtonC;
    $("#divModalFooter").html($("#divModalFooter").html() + 
      '<button type="button" class="btn btn-'+arrButton.strStyle+
      '" id="'+strButtonID+'">'+arrButton.strTitle+'</button>');

  });

    intButtonC = 0;
  $.each(arrButtons, function(intIndex, arrButton){
    intButtonC += 1;
    strButtonID = "btnModalButton" + intButtonC;
    $("#"+strButtonID).unbind().bind("click",arrButton.fncAction);
  });

  $("#divModal").modal();
intButtonC=0;
blnShowWindow=函数(htmlContent、Strttle、arrButtons){
$。每个(arrButtons,函数(intIndex,arrButton){
intButtonC+=1;
strButtonID=“btnModalButton”+intButtonC;
$(“#divModalFooter”).html($(“#divModalFooter”).html()+
''+arrButton.strTitle+'';
});
intButtonC=0;
$。每个(arrButtons,函数(intIndex,arrButton){
intButtonC+=1;
strButtonID=“btnModalButton”+intButtonC;
$(“#”+strButtonID).unbind().bind(“单击”,arrButton.fncAction);
});
$(“#divModal”).modal();

在另一个盒子里,你把所有的按钮都绑在一起

你,我的兄弟,是一个超级英雄!我已经监督过了。非常感谢你!