通过Jquery根据下拉列表中的选择禁用数字字段
Disable Number field based on selection in dropdown via Jquery
我想做的是,如果用户选择"bycrypt",它应该显示一个字段来询问通过了多少次,如果他/她选择"sha512"来显示相同的字段,但被禁用。有人建议我使用Jquery执行此操作,但我的尝试不起作用。我的代码如下:
<fieldset>
<legend>Security</legend>
<label>Hash Type</label>
<select name="hash" id="myId">
<option value="bcrypt"<?php if($hash == 'bcrypt') { echo ' selected="selected"'; } ?>>Bcrypt</option>
<option value="sha512"<?php if($hash == 'sha512') { echo ' selected="selected"'; } ?>>SHA512</option>
</select>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.1.min.js" /></script>
<label>Bcrypt rounds <i>(12 Rounds is recommended)</i></label>
<script type="text/javascript>
$("#myId").change(function() {
var tst = document.getElementById('myId').value;
if (tst ==1) {
document.getElementById('#bcrypt_rounds').disabled=true;
} else {
document.getElementById('#bcrypt_rounds').disabled=false;
}
});
</script>
<input name="bcrypt_rounds" id="bcrypt_rounds" type="text" value="<?php echo $bcrypt_rounds; ? >" />
以上更新。现在剪切"bycrpt_rounds"标签之后的页面。无法访问"bycrypt_ounds"的字段。
类似这样的东西:
<script type="text/javascript">
$("#myId").change(function() {
var tst = document.getElementById('myId').value;
if(tst == "sha512") {
document.getElementById('number_field_id').disabled=true;
} else {
document.getElementById('number_field_id').disabled=false;
}
});
</script>
我认为这应该做
$("#myId").change(function() {
if($(this).val() == 'sha512'){
$('#textBxId').attr({'disabled','disabled'});
}else{
$('#textBxId').removeAttr({'disabled'});
}
});
找到错误,您只需在<script type="text/javascript">
中忘记一个"
<fieldset>
<legend>Security</legend>
<label>Hash Type</label>
<select name="hash" id="myId">
<option value="bcrypt"<?php if($hash == 'bcrypt') { echo ' selected="selected"'; } ?>>Bcrypt</option>
<option value="sha512"<?php if($hash == 'sha512') { echo ' selected="selected"'; } ?>>SHA512</option>
</select>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.1.min.js" /></script>
<label>Bcrypt rounds <i>(12 Rounds is recommended)</i></label>
<script type="text/javascript">
$("#myId").change(function() {
var tst = $('myId').val();
if (tst ==1) {
$('#bcrypt_rounds').attr('disabled','disabled');
} else {
$('#bcrypt_rounds').removeAttr('disabled');
}
});
</script>
<input name="bcrypt_rounds" id="bcrypt_rounds" type="text" value="<?php echo $bcrypt_rounds; ? >" />
相关文章:
- Javascript Regex选择每个非字母数字字符和空白
- 按数字而不是按名称选择JSON对象
- 选择下拉选项时显示数字-javascript
- 使用jQuery可以根据数字选择一组同级
- 不能同时通过类和数字 ID 选择 jquery 元素
- 按数字选择显示输入
- Javascript数字选择器函数
- 如何在输入框中只显示名称,而在选择元素的下拉列表中显示名称和数字
- 如果在JavaScript w/HTML中选择了特定国家/地区,如何要求邮政编码为数字
- 在引导选择组件中的搜索不起作用,其中数据令牌包含所有数字;4730”;
- 下拉列表创建订单,不能在每个下拉列表中选择相同的数字
- 在 jQuery 中选择数字动态元素
- 如何在任意范围内随机选择数字并使用 JavaScript 数组相加
- 使用提示,选择数字的数目,将该数目添加到数组中,然后显示总数
- 在javascript中选择数字范围的算法
- 仅从文本字段中选择数字,加上简单的计算
- Javascript会在下拉菜单中选择数字,并将时间乘以1.09
- jQuery,从id中选择数字,比如“article-23”
- 如何从字符串序列明智地从左到右选择数字整数在javascript
- 使用jQuery或Javascript在页面上选择数字