Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.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
jQuery和split不一起工作?_Jquery - Fatal编程技术网

jQuery和split不一起工作?

jQuery和split不一起工作?,jquery,Jquery,我正在使用jQuery选项卡,并有了一个原型 这是我的密码: $(document).ready(function() { $("#tabs").tabs(); // Select the second tab // $("#tabs").tabs({ selected: 1 }); // http://viralpatel.net/blogs/2009/04/jquery-tabs-create-html-tabs-using-jquery-ui.html $('

我正在使用jQuery选项卡,并有了一个原型

这是我的密码:

$(document).ready(function() {
    $("#tabs").tabs();

  // Select the second tab
  // $("#tabs").tabs({ selected: 1 });

  // http://viralpatel.net/blogs/2009/04/jquery-tabs-create-html-tabs-using-jquery-ui.html
  $('#tabs').bind('tabsselect', function(event, ui) {

    // Objects available in the function context:
    // alert(ui.tab);     // anchor element of the selected (clicked) tab
    var tabPageName = ui.tab;
    alert('Tab Name: ' + tabPageName);

    // var results = tabPageName.substring(tabPageName.IndexOf("#") + 1);
    // alert('Page Name: ' + results);

    var arrData = tabPageName.split("#");
    alert(arrData[1]);

    // alert(ui.panel);   // element, that contains the selected/clicked tab contents
    alert(ui.index);   // zero-based index of the selected (clicked) tab

  });
});
我试图提取锚标记中选项卡的名称:(#fragment-1,等等…)。我尝试使用split方法(IndexOf方法作为替代方法)

这是一位杰出的领袖,他是一位伟大的领袖。 这是一位杰出的领袖,他是一位伟大的领袖。 这是一位杰出的领袖,他是一位伟大的领袖。 这是一位杰出的领袖,他是一位伟大的领袖。 这是一位杰出的领袖,他是一位伟大的领袖。 如您所见,我必须注释掉split()方法,因为我收到以下错误:

未捕获的TypeError:对象没有方法“split”


但是我知道split方法在JavaScript中工作。有人看到我可能缺少什么吗?

您需要将页面名称显式转换为字符串:

var tabPageName = ui.tab.toString();
// choose one - the one you really need
var arrData = tabPageName.split("#")
var results = tabPageName.substring(tabPageName.IndexOf("#") + 1);
使用
alert
时会自动进行转换,但在尝试
split
页面名称时不会进行转换。编写本节的最佳方法是:


这是因为您存储在
tabPageName
变量中的内容实际上不是页面名称,而是选项卡本身,当
alert
ed时返回其名称。

您所说的有道理,我只是从来没有想过JavaScript是一种强类型语言。我现在理解了错误消息。对象类型没有拆分方法。
// DON'T USE THIS - this is a quick & dirty solution, see below for real solution
// choose one - the one you really need
var arrData = tabPageName.toString().split("#")
var results = tabPageName.toString().substring(tabPageName.IndexOf("#") + 1);
var tabPageName = ui.tab.toString();
// choose one - the one you really need
var arrData = tabPageName.split("#")
var results = tabPageName.substring(tabPageName.IndexOf("#") + 1);