下面的代码在加载页面时添加了一个字符串以及输入选择的值。下面的代码有些工作,但在 =
符号后有一个无法识别的长字符串。
我还需要在页面加载时加载代码。
换句话说,当页面加载时,url 还应该包含附加文本。
谁能帮忙?
<script>
$(document).ready(function() {
$("#staff-list").on('change', function() {
location.href = "?account=" + $(this).val;
});
});
</script>
最佳答案
您应该更改您附加 URL 的行,
location.href = "?account="+ $(this).val;
到,
location.href = "?account="+ $(this).val();
并且您希望您的代码返回附加的 URL,您可以这样做,
<script>
$(document).ready(function() {
$("#staff-list").on('change', function() {
$("#id_of_a").attr("href","somefile.php?account=" + $(this.val());
});
});
</script>
我不确定您的代码场景是什么,但这可能会有所帮助。
关于javascript - 将字符串和输入选择值添加到 url onchange 和页面加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44015538/