Last segment of URL

How do I get the last segment of a url? I have the following script which displays the full url of the anchor tag clicked: $(".tag_name_goes_here").live('click', function(event) { event.preventDefault(); alert($(this).attr("href")); }); If the url is http://mywebsite/folder/file how do I only get it to display the "file" part of the url in the alert box? You can also us

URL的最后一部分

如何获取网址的最后一部分? 我有下面的脚本显示了被点击的锚点标签的完整url: $(".tag_name_goes_here").live('click', function(event) { event.preventDefault(); alert($(this).attr("href")); }); 如果网址是 http://mywebsite/folder/file 我怎么才能让它显示警报框中的URL的“文件”部分? 您还可以使用lastIndexOf()函数来查找URL中/字符的最后一次出现位置,然后使用substr()函数返回从该位置开始

How to check string in current URL with javascript?

This question already has an answer here: Get current URL in JavaScript? 29 answers what about this? The regular expression defined at the first line is tested against the URL: var myRe = //series//; //regular expression to use if(myRe.test(window.location.href)){ alert("matching"); }else{ alert("not matching"); } if you want to test for the whole URL (and really want to use a reg

如何检查当前URL中的字符串与JavaScript?

这个问题在这里已经有了答案: 在JavaScript中获取当前网址? 29个答案 那这个呢? 在第一行定义的正则表达式将根据URL进行测试: var myRe = //series//; //regular expression to use if(myRe.test(window.location.href)){ alert("matching"); }else{ alert("not matching"); } 如果你想测试整个URL(并且真的想用正则表达式),你可以用第一行代替 var myRe = /^http://mywebsite/series/2545-abc$/; 如果

How do get URL in javascript?

This question already has an answer here: Get current URL in JavaScript? 29 answers To get the entire current URL, use: var currentURL = window.location; Then to get the hash, without the # itself, use: var trimmedHash = window.location.hash.substr(1); // returns `21` from `xxxx.com/#21` window.location.hash returns #21, and substr(1) returns all but the first character of that string, t

如何在JavaScript中获取URL?

这个问题在这里已经有了答案: 在JavaScript中获取当前网址? 29个答案 要获取整个当前网址,请使用: var currentURL = window.location; 然后得到散列,没有#本身,使用: var trimmedHash = window.location.hash.substr(1); // returns `21` from `xxxx.com/#21` window.location.hash返回#21,substr(1)返回除该字符串的第一个字符以外的所有字符,从而删除# 。 使用下一个: HREF = document.location.href

How to get current URL with JavaScript?

This question already has an answer here: Get current URL in JavaScript? 29 answers If you are currently on http://store.ijdmtoy.com/abs.htm then document.URL will be http://store.ijdmtoy.com/abs.htm . You can try: url = location.protocol + '//' + location.host + location.pathname + '?Search=' + str; You can use document.URL or window.location.href.toString

如何使用JavaScript获取当前网址?

这个问题在这里已经有了答案: 在JavaScript中获取当前网址? 29个答案 如果您目前位于http://store.ijdmtoy.com/abs.htm,那么document.URL将为http://store.ijdmtoy.com/abs.htm 。 你可以试试: url = location.protocol + '//' + location.host + location.pathname + '?Search=' + str; 您可以使用 document.URL or window.location.href.toString() 我希望你的意思是这个 http

Detect current page with JavaScript

This question already has an answer here: Get current URL in JavaScript? 29 answers 例如,您可以通过执行以下操作来获取URL: window.location.href If you want to know what age they are on, it really depends on the url structure. But you will get the information with window.location.pathname var pathname = window.location.pathname; switch(pathname) { case "/home" : console.log("home

使用JavaScript检测当前页面

这个问题在这里已经有了答案: 在JavaScript中获取当前网址? 29个答案 例如,您可以通过执行以下操作来获取URL: window.location.href 如果你想知道他们在什么年龄,这真的取决于网址结构。 但是,您将通过window.location.pathname获取信息 var pathname = window.location.pathname; switch(pathname) { case "/home" : console.log("home"); break; case "/game" : console.log("game");

Remove everything after domain and http in url javascript

This question already has an answer here: Get current URL in JavaScript? 29 answers You can try this: //([^/,s]+.[^/,s]+?)(?=/|,|s|$|?|#) Regex live here. Live JavaScript sample: var regex = ///([^/,s]+.[^/,s]+?)(?=/|,|s|$|?|#)/g; var input = "https://www.google.com/hello/hi.php, http://youtube.com," + "http://test.net#jump or http://google.com?q=test"; while (match =

删除javascript和url中的域和http之后的所有内容

这个问题在这里已经有了答案: 在JavaScript中获取当前网址? 29个答案 你可以试试这个: //([^/,s]+.[^/,s]+?)(?=/|,|s|$|?|#) 正则表达式住在这里。 现场JavaScript示例: var regex = ///([^/,s]+.[^/,s]+?)(?=/|,|s|$|?|#)/g; var input = "https://www.google.com/hello/hi.php, http://youtube.com," + "http://test.net#jump or http://google.com?q=test"; while (match = regex.exec(input

How do I escape a string inside JavaScript code inside an onClick handler?

Maybe I'm just thinking about this too hard, but I'm having a problem figuring out what escaping to use on a string in some JavaScript code inside a link's onClick handler. Example: <a href="#" onclick="SelectSurveyItem('<%itemid%>', '<%itemname%>'); return false;">Select</a> The <%itemid%> and <%itemname%> are where template substitution occurs.

如何在onClick处理程序中的JavaScript代码中转义字符串?

也许我只是想这太难了,但我有一个问题搞清楚在链接的onClick处理程序内的一些JavaScript代码中使用字符串的内容。 例: <a href="#" onclick="SelectSurveyItem('<%itemid%>', '<%itemname%>'); return false;">Select</a> <%itemid%>和<%itemname%>是模板替换发生的地方。 我的问题是项目名称可以包含任何字符,包括单引号和双引号。 目前,如果它包含单引号,则会打破JavaScript代

Difference between val() and text()

What the difference between jQuery's functions val() and text() ? Where would you use one over the other? .val() works on input elements (or any element with a value attribute?) and .text() will not work on input elements. .val() gets the value of the input element -- regardless of type. .text() gets the innerText (not HTML) of all the matched elements: .text() The result is a strin

val()和text()之间的区别

jQuery的函数val()和text()之间的区别是什么? 你会在哪里使用一个? .val()对输入元素(或任何带有value属性的元素.val()起作用,而.text()对输入元素不起作用。 .val()获取输入元素的值 - 无论类型如何。 .text()获取所有匹配元素的innerText(不是HTML): .text() 结果是一个包含所有匹配元素的组合文本内容的字符串。 此方法适用于HTML和XML文档。 不能用于输入元素。 对于输入字段文本,使用val属性。 .val(

javascript websocket onmessage event.data

Using JavaScript WebSocket how to pass event.data out onMessage function? var eventData = EventRequest("text"); ..... codes ..... EventRequest = function (text) { var socket = new WebSocket ('ws://localhost:8080/'); websocket.onopen = function(evt) { onOpen(evt); }; websocket.onmessage = function(evt) { onMessage(evt); }; function onOpen (evt) { socket.send("text"); } functio

javascript websocket onmessage event.data

使用JavaScript WebSocket如何将event.data传递给onMessage函数? var eventData = EventRequest("text"); ..... codes ..... EventRequest = function (text) { var socket = new WebSocket ('ws://localhost:8080/'); websocket.onopen = function(evt) { onOpen(evt); }; websocket.onmessage = function(evt) { onMessage(evt); }; function onOpen (evt) { socket.send("text"); } function onMessage

How to encode square brackets in spring url?

I have a path variable which has square brackets in spring url.But i am getting bad reuqest for the same. I am encoding the url in backbone framework using encodeUriComponent. But still even after url being encoded correctly i am getting bad request. 实际上问题是因为路径变量中的反斜杠,它需要一个双重编码才能正确编码。

如何编码春季url中的方括号?

我有一个路径变量,它在春天url中有方括号。但是我变得很糟糕reuqest相同。 我在使用encodeUriComponent的骨干框架中编码url。 但即使在URL正确编码后,我仍然收到不好的请求。 实际上问题是因为路径变量中的反斜杠,它需要一个双重编码才能正确编码。