私はopencartのビューファイルで作業しています。私は日付と時刻をそれぞれ設定する2つのテキストボックスを持っています。私はチェックボックスを持っています。その値はチェックされているとき1、チェックされていないとき0です。上記のチェックボックスがオンの場合は、日付と時刻のフィールドを非表示にする必要があります(完了まで)。彼らは今(現在まで)完了です。 現在のコード:HTMLでJS関数を呼び出す方法
HTML
<tr id="row_ship_date">
<td>
Shipment Date:
</td>
<td>
<input type="text" id="ship_date" name="ship_date" class="date" onchange="getServices();" />
</td>
</tr>
<tr id="row_ship_time">
<td>
Shipment Time:
</td>
<td>
<input type="text" id="ship_time" name="ship_time" class="time" />
</td>
</tr>
<?php
if (isset($current_date_shipment) && $current_date_shipment == 1) // check box value check{?>
<script type="text/javascript">
document.getElementById('row_ship_date').style.display='none';
document.getElementById('row_ship_time').style.display='none';
getServices();
</script>
<?php }
?>
JS:
function getServices() {
alert('test');
var ship_date = $('#ship_date').val();
var ship_time = $('#ship_time').val();
// code so on..
}
現在の問題
1)チェックボックスのチェックがtrueの場合、私はgetServices()
を呼び出すことができません(のPHPチェックif
ステートメント)そのfalseの場合は、dateのonchangeイベントを呼び出しますうまく動作します。私はあなたの構文を推測
function getServices() {
alert('test');
var ship_date = new Date();
var ship_time = currentTime();
// code so on..
}
PHPの条件が真である場合にブラウザコンソールをチェックしてください.JSエラーがあるかもしれません。 –
PHPの条件が真を返す場合は、コードに問題はないようです(コメントステートメント//チェックボックスの値のチェックは中括弧 "{") –
@ techie_28をコメントしていますが、なぜ私の関数が得られないのかいわゆる(JS関数)。 –