【问题标题】:HTML post specific value on submit提交时的 HTML 帖子特定值
【发布时间】:2015-11-14 05:49:58
【问题描述】:
我有一个搜索栏,我试图拦截 POST,附加“tag:”,然后提交它,如果有人在搜索栏中输入“apple”,它就会出现 tag:apple
<form method="get" action="/search" id="search-home">
<button type="submit" value="search"></button>
<input type="hidden" name="type" value="product" />
<input type="text" name="q" placeholder="Search" />
</form>
【问题讨论】:
标签:
javascript
jquery
html
search
【解决方案1】:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
</head>
<body>
<form method="get" action="/search" id="search-home">
<button type="submit" value="search">submit</button>
<input type="hidden" name="type" value="product" />
<input type="text" name="q" placeholder="Search" class="searchtext"/>
</form>
<script>
$(document).on('submit','#search-home',function(){
var searchtext = $('.searchtext').val();
$('.searchtext').val("tag:"+searchtext);
});
</script>
</body>
</html>