0
$('#').change(function () {
    var php_var2 = "<?php echo $br; ?>";
    var php_var3 = "<?php echo $rb; ?>";
    if ($(this).val() == 'NEGOTIATED' || $(this).val() == 'SHOPPING') {
        $("#txt36,#txt49").val('');
    } else if {
        //here you can specify what to do if the value is NOT negotiated or SHOPPING
        $("#txt36").val(php_var2);
    } else {
        //here you can specify what to do if the value is NOT negotiated or SHOPPING
        $("#txt49").val(php_var3);
    }
});

2 つのテキスト ボックス txt36、txt49 があり、onchange イベントを選択します。NEGOTIATED または SHOPPING を選択すると、txt36 と txt49 の値は " " に等しくなり、RFQ を選択すると、txt36 の値は none になります。BIDDING を選択すると、txt49 の値も none になります。しかし、このコードは機能しませんでした。

4

2 に答える 2

0

しかし、このコードは機能しませんでした。

使用したのは#

$('#').change(function(){ // ... });

はどこidですか?それは、次のようなものでなければなりません

$('#selectId').change(function(){ // ... }); // <select id="selectId">

また

$('select').change(function(){ // ... }); // using the tag name

また

$('.selectClass').change(function(){ // ... }); // if it has a class, i.e. <select class="selectClass">

また、else ifのような条件が必要else if(condition)です。しかし、私は、あなたが使用できると思います

if ($(this).val() == 'NEGOTIATED' || $(this).val() == 'SHOPPING') {
    $("#txt36,#txt49").val('');
}
else if ($(this).val() == 'RFQ') {
    $("#txt36").val('');
}
else if ($(this).val() == 'BIDDING') {
    $("#txt49").val('');
}
else {
    //here you can specify what to do if the value is NOT negotiated or SHOPPING
    $("#txt36").val(php_var2);
    $("#txt49").val(php_var3);
}
于 2013-09-24T01:47:39.087 に答える
0

2 つの間違いがあります。

  • 最初のセレクターが間違っています:$("#")
  • else if条件がありません:else if(...) {

これを試して:

$('select').change(function () {
    var php_var2 = "<?php echo $br; ?>";
    var php_var3 = "<?php echo $rb; ?>";
    if ($(this).val() == 'NEGOTIATED' || $(this).val() == 'SHOPPING') {
        $("#txt36,#txt49").val('');
    } else {
        //here you can specify what to do if the value is NOT negotiated or SHOPPING
        $("#txt49").val(php_var3);
    }
});
于 2013-09-24T01:50:34.623 に答える