我有两个字段选择框和文本框如何比较这两个框值?
文字框如:
<input type="text" name="u_position" value="<?php echo $row->role_des;?>" style="border:none;" readonly>
And Select box like:
<select class="form-control" placeholder="designation" value="<?php echo set_value('design');?>" name="design" required>
<option value="">--Select---</option>
<option value="Supervisor">Supervisor</option>
<option value="Salessupervisor">Sale Supervisor</option>
</select>
<button type="submit" class="btn btn-success">Submit</button>
点击按钮进行比较。请帮助我,提前谢谢。
答案 0 :(得分:0)
你可以使用这样的jquery来做到这一点:
$(document).ready(function(){
$('select').on('change',function(){
if($(this).val() == $('input:eq(0)').val() == $('input:eq(1)').val() == $('input:eq(2)').val())
{
//You can do your further code here
}
});
});
答案 1 :(得分:0)
在select元素中包含一个onchange属性,该属性将调用javascript函数。在函数调用中,通过它的ID访问文本框元素并实现您的逻辑。
HTML代码:
enable multidex,
1. Add following dependency in app gradle file compile
'com.android.support:multidex:1.0.1' and
defaultConfig {
multiDexEnabled true
}
2. Your application class need to extends MultiDexApplication
Javascript代码:
<input id="textBoxId" type="text" name="u_position" value="<?php echo $row->role_des;?>" style="border:none;" readonly>
<select class="form-control" placeholder="designation" value="<?php echo set_value('design');?>" name="design" required onchange="compareVal(this.value)">
<option value="">--Select---</option>
<option value="Supervisor">Supervisor</option>
<option value="Salessupervisor">Sale Supervisor</option>
</select>
答案 2 :(得分:0)
试试这个:
<input type="text" name="u_position" value="<?php echo $row->role_des;?>" style="border:none;" readonly>
And Select box like:
<select class="form-control" placeholder="designation" value="<?php echo set_value('design');?>" name="design" required>
<option value="">--Select---</option>
<option value="Supervisor">Supervisor</option>
<option value="Salessupervisor">Sale Supervisor</option>
</select>
<button type="submit" onclick="checkVals();return false;" class="btn btn-success">Submit</button>
这是javascript:
function checkVals() {
var a = $('input[name="u_position"]').val();
var b = $('.form-control').find(":selected").val();
console.log('this is selected: ' + b + ' ---- and this is text input: ' + a)
if (a === b) {
// do something
}
}