我有html视图,其中它是一个作为字符串的搜索栏。所需部分的代码如下。 那么,如何正确地将值从搜索栏输入到URL字符串呢? 我只能使用html还是需要使用js?
<form class="navbar-search navbar-search-dark form-inline mr-3 d-none d-md-flex ml-lg-auto" method="get"
action="/search/" >
<div class="form-group mb-0">
<div class="input-group input-group-alternative">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-search"></i></span>
</div>
<input class="form-control" id="mySearch" placeholder="Search" type="search" value >
</div>
</div>
</form>.
答案 0 :(得分:0)
我不知道它如何与表单一起使用,也许这可以帮助您拉近距离?
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$('#dynam-now').click(function () {
console.log($('#mySearch').val())
});
});
</script>
<form class="navbar-search navbar-search-dark form-inline mr-3 d-none d-md-flex ml-lg-auto" method="get"
action=$('#mySearch').val()" >
<div class="form-group mb-0">
<div class="input-group input-group-alternative">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-search"></i></span>
</div>
<input class="form-control" id="mySearch" placeholder="Search" type="search" value >
</div>
</div>
</form>
<button id="dynam-now">Click to search</button>