gpt4 book ai didi

javascript - 如何使用 Jquery 检查 URL 参数值是否存在?

转载 作者:行者123 更新时间:2023-12-03 06:21:54 29 4
gpt4 key购买 nike

<select onchange="select_serviceid();" id="exist_service" name="exist_service" class="validate[required] form-control">
<option value="">Select from existing Service Apartment</option>
<option value="1">test123</option>
<option value="2">Test Provab</option>
<option value="3">Test Provab</option>
<option value="4">Test Provab dated</option>
<option value="5">Test Provab123456789</option>
</select>
<script>
function select_serviceid(){
var select1 = $( "#exist_service option:selected" ).val();
var url = document.URL+'?service='+select1;
$(location).attr('href', url);
}
</script>

这里我将服务 ID 重定向到 URL 并重新加载它,但我想首先检查当前 URL 中是否有可用的参数。如果不是,那么我添加参数,否则仅更改 id 值。

这是网址

http://192.168.0.24/corporate_rooms/CRS/property/service_basicinfo?service=3

参数服务想要在加载时更改

最佳答案

在选择功能中

onchange="getServiceId(this);" # To pass the value use this parameter

在 JQuery 中

function getServiceId(sel) {
var id = sel.value;
if(id == '')
{
alert('empty');
}
else
{
# Your code here
}
}
<小时/>

编辑01

Get current URL in web browser

var url = window.location.href+'?service='+id;

How to redirect to another page in jQuery?

// similar behavior as an HTTP redirect
window.location.replace(url);

// similar behavior as clicking on a link
window.location.href = url;

关于javascript - 如何使用 Jquery 检查 URL 参数值是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38829706/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com