Javascript 不会检查文本输入值是否随组合网格而变化
Javascript doesn't check text input value changing with combogrid
>我尝试了在其他讨论中提出的不同方法来检查文本输入的值是否更改。但是我还没有找到适合我的解决方案。你可以帮我吗?我有一个表格这个主页:
<?php
$pdo = new PDO("mysql:host=localhost;dbname=db_nvh;charset=utf8", "root", "root");
?>
<html>
<head>
<link type="text/css" rel="stylesheet" href="style.css"/>
<link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">
<script type="text/javascript" src="easyui/jquery.min.js"></script>
<script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
<script type="text/javascript">
$(function(){
$('#id_car').combogrid({
panelWidth:500,
url: 'form5_getdata.php',
idField:'id_car',
textField:'id_car',
mode:'remote',
fitColumns:true,
columns:[[
{field:'id_car',title:'Car ID',width:60},
{field:'brand',title:'Brand',align:'right',width:80},
{field:'model',title:'Model',align:'right',width:80},
{field:'chassis',title:'Chassis',align:'right',width:60},
{field:'db_proto',title:'Db proto',width:150}
]]
});
});
</script>
<script type="text/javascript">
$(function() { // This code will be executed when DOM is ready
$('#id_car').change(function() { // When the value for the id_car element change, this will be triggered
var $self = $(this); // We create an jQuery object with the select inside
$.post("getCarData.php", { id_car : $self.val()}, function(json) {
if (json && json.status) {
$('#brand').val(json.brand);
$('#model').val(json.model);
$('#gear_box_type').val(json.gear_box_type);
if(json.sunroof === 'yes'){
// var var_name = $("input[name='sunroof2']:checked").val();
$('#sunroof2').attr('checked', 'checked');
} else { // var var_name = $("input[name='sunroof1']:checked").val();
$('#sunroof1').attr('checked', 'checked'); } ;
}
var element = document.getElementById('gear_box_type');
element.value = json.gear_box_type;
})
});
})
</script>
<title>RPT</title>
</head>
<body>
<div id="content">
<h1 align="center">Test page</h1>
<form action="inserttraining.php" method="post">
<div>
<p>
<input type="text" name="id_car" id="id_car" style="width:150px"></input>
<p>
Brand:
<input type="text" name="brand" id="brand">
</p>
<p>
Model:
<input type="text" name="model" id="model">
</p>
<?php
include("dbconnect.php");
$gear_box_typequery = "SELECT `gear_box_type` FROM `gear_box_type`";
$result = mysqli_query($conn,$gear_box_typequery);
echo "<label for=''>  Gearbox Type:</label><br><select id='gear_box_type' name='gear_box_type'>";
while ($row = mysqli_fetch_array($result)) {
echo "<option "; echo "value='" . $row['gear_box_type'] ."'>" . $row['gear_box_type'] ."</option>";
}
echo "</select>";
?>
<label for=''>  No</label><input type="radio" id="sunroof1" name="sunroof" value="no" >
<label for=''>  Yes</label><input type="radio" id="sunroof2" name="sunroof" value="yes">
<input type="submit">
</form>
</div>
</body>
</html>
当用户从第一个文本输入中选择其他文本输入的值时,必须根据从mysql数据库加载的值设置单选按钮和下拉菜单。如果我使用简单的选择输入来选择添加到数据库中的汽车,javascript 工作正常,它会检查所选值何时更改。如果我使用带有简单文本输入的 combbogrid,它不能正常工作,javascript 不会检查任何更改,并且数据未从 ajax 的数据库中加载。我该如何解决?
更新 1
我尝试过这种方式:
$(function() {
onSelect:function(record){
$('#id_car').combogrid({
var $self = $(this); // We create an jQuery object with the select inside
$.post("getCarData.php", { id_car : $self.val()}, function(json) {
if (json && json.status) {
$('#brand').val(json.brand);
$('#model').val(json.model);
$('#gear_box_type').val(json.gear_box_type);
if(json.sunroof === 'yes'){
// var var_name = $("input[name='sunroof2']:checked").val();
$('#sunroof2').attr('checked', 'checked');
} else { // var var_name = $("input[name='sunroof1']:checked").val();
$('#sunroof1').attr('checked', 'checked'); } ;
}
var element = document.getElementById('gear_box_type');
element.value = json.gear_box_type;
})
});
}
}
})
但它不起作用。不知道是不是有什么不对劲。
您需要使用 onSelect:function(record){...}
事件来获取所选值。
<script type="text/javascript">
$(function(){
$('#id_car').combogrid({
panelWidth:500,
url: 'form5_getdata.php',
idField:'id_car',
textField:'id_car',
mode:'remote',
fitColumns:true,
columns:[[
{field:'id_car',title:'Car ID',width:60},
{field:'brand',title:'Brand',align:'right',width:80},
{field:'model',title:'Model',align:'right',width:80},
{field:'chassis',title:'Chassis',align:'right',width:60},
{field:'db_proto',title:'Db proto',width:150}
]],
// use onSelect: function(index,row) {...} to get selected row value, ie. row.id_car
onSelect: function(index,row) {
var $selected = row.id_car; // Get the selected row id_car
$.post("getCarData.php", { id_car : $selected}, function(json) {
if (json && json.status) {
$('#brand').val(json.brand);
$('#model').val(json.model);
$('#gear_box_type').val(json.gear_box_type);
if(json.sunroof === 'yes'){
// var var_name = $("input[name='sunroof2']:checked").val();
$('#sunroof2').attr('checked', 'checked');
} else { // var var_name = $("input[name='sunroof1']:checked").val();
$('#sunroof1').attr('checked', 'checked'); } ;
}
var element = document.getElementById('gear_box_type');
element.value = json.gear_box_type;
}
});
}
});
});
</script>
这是一个 JSFiddle 示例 - http://jsfiddle.net/kuv5ao8f/
相关文章:
- 当在EXTJS中的网格中使用时,afterrender不适用于组合框
- 如何在javascript中设置网格组合框值
- RefreshFilter在DHTMLX网格中不起作用.当我使用自定义组合框时
- 在组合框筛选后执行回调网格视图
- 剑道网格:如何在与Angular一起使用时从组合框单元格模板中获取所选项目
- Extjs 网格列 - 组合在值更改后显示键而不是值
- 网格中的组合框
- 具有多个网格和组合的hbox/vbox布局的ExtJS窗口在Internet Explorer上渲染得非常慢
- Javascript 不会检查文本输入值是否随组合网格而变化
- 节点 - 用于发送电子邮件的选项,发送网格和节点邮件之一或组合
- 如何在 ExtJS5 中网格编辑器组合的当前记录中添加项目
- 如何使用网格配置Kendo UI组合框
- 需要在剑道网格内的组合框中进行验证
- Sencha ExtJS 4.2:如何在一个网格中同步两个组合编辑器
- 如何将组合框用作剑道 UI 网格列
- easyUI数据网格内部编辑组合框无法选择默认值
- 剑道网格内的剑道组合框编辑不起作用
- 在extjs网格中添加只有一行的组合框
- 在ExtJS网格面板中,如何使用ChainedStore和widgetcolumn来显示每行具有不同值的组合框
- Extjs网格与可编辑的组合框列