javascript - 通过ajax获取值
问题描述
谁能帮我处理ajax?此代码工作正常,但如何将复选框、选择和单选按钮的值传输到其他页面?我想在页面 main_search_find.php 上获取该值,然后在页面 index.php 中显示
我无法在 main_search_find.php 页面上传输值
解决方案
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>serialize demo</title>
<style>
body, select {
font-size: 12px;
}
form {
margin: 5px;
}
p {
color: red;
margin: 5px;
font-size: 14px;
}
b {
color: blue;
}
</style>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
</head>
<body>
<form>
<select name="single">
<option>Single</option>
<option>Single2</option>
</select>
<br>
<select name="multiple" multiple="multiple">
<option selected="selected">Multiple</option>
<option>Multiple2</option>
<option selected="selected">Multiple3</option>
</select>
<br>
<input type="checkbox" name="check" value="check1" id="ch1">
<label for="ch1">check1</label>
<input type="checkbox" name="check" value="check2" checked="checked" id="ch2">
<label for="ch2">check2</label>
<br>
<input type="radio" name="radio" value="radio1" checked="checked" id="r1">
<label for="r1">radio1</label>
<input type="radio" name="radio" value="radio2" id="r2">
<label for="r2">radio2</label>
</form>
<p><tt id="results"></tt></p>
<script>
function showValues() {
var str = $( "form" ).serialize();
$( "#results" ).text( str );
}
$( "input[type='checkbox'], input[type='radio']" ).on( "click", showValues );
$( "select" ).on( "change", showValues );
showValues();
</script>
</body>
</html>
推荐阅读
- matlab - 如何在 MatCont MATLAB 中为两个方程系统运行 Hopf 曲线?
- c++ - 打印出浮点/双变量以进行硬件验证
- xslt-1.0 - 使用调用模板参数时的 Xalan 性能问题
- amazon-s3 - 无服务器 s3 事件监听器
- r - 在 R 中使用 scale() 进行 z 变换
- javascript - 如何为给定的字符串编写正则表达式 -Regex Javascript
- javascript - noUiSlider 将点转换为对数外观
- php - PHP函数用于解码具有不同编码的字符串
- angularjs - AngularJS 删除 $http.get 中的 `x-csrf-token`
- python - cffi 模块已构建但在导入时未找到