2
<div id="main">
<div class="navigate">
    <ul>
        <li>
            <a href="http://localhost/xm/index.php"><span>xm</span></a> &#187;
        </li>
        <li>
            <a href="http://localhost/xm/index.php?action=admin"><span>Admin</span></a> &#187;
        </li>
        <li>
            <a href="http://localhost/xm/index.php?action=admin;change=name;random02342=randomvaluetoo320230"><span>change</span></a>
            .......

从这个 html 代码中,我必须在变量中获取随机生成的数据“random02342=randomvaluetoo320230”,这也是随机生成的 random0234 和随机值。我如何通过 Javascript(或非 jquery)实现这一点?

编辑:random02342 和 randomvaluetoo320230 是在服务器端随机生成的。所以就像每次新哈希一样 1stHash4324kjkjdas324324=And2ndAnotherHash324324asd23432

4

3 回答 3

2

这会得到它,尽管它可能不会因优雅而赢得任何奖项:

var m = document.getElementById('main').innerHTML.match(/random(\d+)=randomvaluetoo(\d+)/);
// m[1] and m[2] are the two random values.
于 2012-09-30T23:59:43.177 回答
0
var first, second;

var q = $('.navigate ul li a[href*="change=name"]').attr('href').split(';').filter(
    function() {
        return this.contains('random');
    }
).join().replace(/[a-zA-z]/g, '').split('=');

first = q[0];
second = q[1];
于 2012-10-01T00:13:34.943 回答
0

based on your comment:

var value = $('selector').attr('href').split(';')[2].split('=');

this will give you value[0] - name, and value[1] - value However this is only if there 3 query params and the random one is the third

Also this might be usefull Parse query string in JavaScript

于 2012-10-01T00:32:23.840 回答