Php 通过Jquery根据下拉列表中的选择禁用数字字段

Php 通过Jquery根据下拉列表中的选择禁用数字字段,php,javascript,jquery,Php,Javascript,Jquery,我想做的是,如果用户选择“bycrypt”,它应该显示一个字段来询问通过了多少次,如果用户选择“sha512”来显示相同的字段,但被禁用。有人建议我使用Jquery执行此操作,但我的尝试无效。 我的代码如下: <fieldset> <legend>Security</legend> <label>Hash Type</label> <select name="hash" id="myId">

我想做的是,如果用户选择“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; ?       >" />  

安全
散列类型
>SHA512
Bcrypt轮(建议12轮)
大概是这样的:

<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(函数(){
var tst=document.getElementById('myId')。值;
如果(tst==“sha512”){
document.getElementById('number\u field\u id')。disabled=true;
}否则{
document.getElementById('number\u field\u id')。disabled=false;
}
});
我想这应该可以

$("#myId").change(function() { 
    if($(this).val() == 'sha512'){
      $('#textBxId').attr({'disabled','disabled'});
    }else{
      $('#textBxId').removeAttr({'disabled'});
    }
});

找到错误,您只是忘记了
中的


安全
散列类型
>SHA512
Bcrypt轮(建议12轮)
$(“#myId”).change(函数(){
var tst=$('myId').val();
如果(tst==1){
$('bcrypt_rounds').attr('disabled','disabled');
}否则{
$('bcrypt_rounds')。removeAttr('disabled');
}
});

你能给我们看看你的
toBuff()
函数吗?@Aelios我四处寻找帮助,看到有几个人在使用这个函数。我想它是一个Javascript函数(内置的,像document.write,但专门用于代码).恐怕这不是我们的内置功能Javascript@Aelios好的,所以我要做的就是在页面上写一些HTML。我可以改为document.write()?是的!看我的回答,它没有打印输入字段。不,仍然会切断页面,并且永远无法写入字段。如果发现错误,您只需忘记一个
中的
。找到脚本声明中缺少的
。快速提问,是否有方法也可以更改禁用字段的值。现在,我将字段值默认为12,但当它变为禁用时,我想将其更改为“禁用”或其他内容。
$('#bcrypt_rounds').val(“禁用”)
@chriscct7:你应该看到关于我问题的评论,你应该早点找到答案。。。
<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; ?       >" />