Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.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 正在修复URl,以便没有空格_Javascript_Jquery_Html - Fatal编程技术网

Javascript 正在修复URl,以便没有空格

Javascript 正在修复URl,以便没有空格,javascript,jquery,html,Javascript,Jquery,Html,我有一个通过jquery动态生成其位置的按钮: <a id="final_location" href="/pre_config/step4" class="proceed-btn right">Proceed To Next Step &gt;&gt;&gt;</a> 这非常有效,但当类型为\u的\u站点中的html是两个单词时,问题就出现了。。。我得到这个网址: pre_config/step4/Pizza Delivery/

我有一个通过jquery动态生成其位置的按钮:

<a id="final_location" 
   href="/pre_config/step4" 
   class="proceed-btn right">Proceed To Next Step &gt;&gt;&gt;</a>
这非常有效,但当类型为\u的\u站点中的html是两个单词时,问题就出现了。。。我得到这个网址:

pre_config/step4/Pizza Delivery/2
有没有办法让url只给我这样的第一个词:

pre_config/step4/Pizza/2
也许可以更改为只返回第一个单词?

使用

encodeURIComponent($('#type_of_station').text().match(/^\S*/)[0])
而不是
escape($('#键入_of_station').html())
来获取第一个单词(用空格分隔)

使用

encodeURIComponent($('#type_of_station').text().match(/^\S*/)[0])

而不是
escape($('#键入_of_station').html())
来获取第一个单词(用空格分隔)

这应该是短语中的第一个单词:

var type = $('#type_of_station').html();
var i = type.indexOf(' ');
if (i != -1) type = type.substr(0, i);

这应该是短语中的第一个单词:

var type = $('#type_of_station').html();
var i = type.indexOf(' ');
if (i != -1) type = type.substr(0, i);
你可以做:

var name = "Pizza Delivery";
var pieces = name.split(" ");

alert(pieces[0]); // Pizza
或者干脆做:

var name = "Pizza Delivery";
name = name.replace(/\s/g, "-", name); // feel free to change the - delimiter

alert(name); // Pizza-Delivery
你可以做:

var name = "Pizza Delivery";
var pieces = name.split(" ");

alert(pieces[0]); // Pizza
或者干脆做:

var name = "Pizza Delivery";
name = name.replace(/\s/g, "-", name); // feel free to change the - delimiter

alert(name); // Pizza-Delivery