这是两个选择。我想选择一个按钮链接,并必须通过post方法获得值时,我提交的表格请,我如何去做呢?若要捕获具有数据值以供出租的链接的值,请单击数据值以供出租,而对于待售的数据值,反之亦然,然后当我单击submit按钮时,我希望捕获该值并将其与搜索按钮相关联。
<div class="mxw-670 position-relative z-index-2">
<input class="search-field" type="hidden" name="status" value="for-sale" data-default-value="">
<ul class="nav nav-pills property-search-status-tab">
<li class="nav-item" role="presentation">
<a class="nav-link btn shadow-none rounded-bottom-0 fs-13 letter-spacing-087 bg-dark-opacity-05 text-white hover-white text-uppercase bg-active-primary active"
data-toggle="pill" data-value="for-sale" href="#" role="tab" aria-selected="true" form="message">
sale
</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link btn shadow-none rounded-bottom-0 fs-13 letter-spacing-087 bg-dark-opacity-05 text-white hover-white bg-active-primary text-uppercase"
data-toggle="pill" data-value="for-rent" href="#" role="tab" aria-selected="false" form="message">
rent
</a>
</li>
</ul>
<form action="" method="post" id="message" class="d-flex">
<div class="position-relative w-100">
<i class="far fa-search text-dark fs-18 position-absolute pl-4 pos-fixed-left-center"></i>
<input type="text"
class="rounded-bottom-right-lg w-100 pl-8 py-4 bg-white border-0 fs-13 font-weight-500 text-gray-light rounded-0 lh-17"
placeholder="Enter an address, neighborhood" name="search">
</div>
<button type="submit" name="submit" class="btn btn-primary fs-16 font-weight-600 rounded-left-0 rounded-lg">
Search
</button>
</form>
</div>发布于 2022-11-25 09:09:55
将按钮设置为input type button,并使用jQuery Ajax调用提交表单
<input type="button" id="submitButton" name="submit" class="btn btn-primary fs-16 font-weight-600 rounded-left-0 rounded-lg" value="Search" />在你的javascript代码中
$('input#submitButton').click( function() {
$.post( 'some-url', $('form#myForm').serialize(), function(data) {
// ... do something with the response from the server
},
'JSON' // I expect a JSON response
);
});
$('input#submitButton').click( function() {
$.ajax({
url: 'some-url',
type: 'post',
dataType: 'json',
data: $('form#myForm').serialize(),
success: function(data) {
// ... do something with the data...
}
});
});在data调用的ajax字段中,可以使用$(element).attr('data-value')添加具有data-value属性的链接的值。
https://stackoverflow.com/questions/74570326
复制相似问题