Grab the youtube Video ID with Jquery & .match()

前端 未结 2 1066
梦谈多话
梦谈多话 2021-02-11 04:09

Just need a little push as I have this almost working.

I want to feed jquery a URL and have it strip everthing but the video url.

Here is my code:



        
2条回答
  •  忘掉有多难
    2021-02-11 04:57

    First, remove the $ in front of results... I assume that was a typo. Next, replace

    $results = url.match("[\\?&]v=([^&#]*)");
    

    with

    results = url.match("[\?&]v=([^&#]*)")[1];
    

    match() will return an array if there is a successful match. You're currently getting the entire array. What you want is the second element of the array (match()[1]) which is what is inside your capturing parentheses.

提交回复
热议问题