我想在菜单中将所有这个SID = xxxx替换为SID = yyyy
<ul class="menu">
<li><a href="http://localhost:11111/controller1/action1?SID=21212121">Menue 1</a></li>
<li><a href="http://localhost:11111/controller1/action2?SID=21212121">Menue 2</a></li>
<li><a href="http://localhost:11111/controller1/action3?SID=21212121">Menue 3</a></li>
</ul>
我从回调中获得了一个新的SID值来替换旧值
$http.post(sUrl,sPostData).then(function(controller1Response) {
$scope.result = controller1Response.data.ResultSet.result;
$scope.SID = controller1Response.data.ResultSet.SID;
});
$ scope.SID获得了新的新值。
答案 0 :(得分:0)
类似的东西:
var newSID = '45454545'
$('#btn').on('click', function() {
$('a').each(function() {
var href = $(this).attr('href').replace(/SID=[0-9]+/g, 'SID=' + newSID);
$(this).attr('href', href);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="menu">
<li><a href="http://localhost:11111/controller1/action1?SID=21212121">Menue 1</a></li>
<li><a href="http://localhost:11111/controller1/action2?SID=21212121">Menue 2</a></li>
<li><a href="http://localhost:11111/controller1/action3?SID=21212121">Menue 3</a></li>
</ul>
<button id='btn'>click me</button>