php - 是否可以在 php 类中包含 <script type ="text/javascript"> ?

标签 php javascript jquery

如果是的话..是如何完成的?我知道这可能是一个愚蠢的问题,但我不确定它是如何完成的。下面这个脚本:

<script type="text/javascript">
$(document).ready(function(){
$('charge_amt').keyup(function(){
    var that = this;
    $('#charge_cc').prop('checked', function(){
        return that.value.length;
    });
}); 
});
</script>

我如何将它集成到这个类中:

class OkToShipEDPump extends \Komment
    {
    /**
        Declare any autofill data.
        */
    protected function my_data()
        {
        }

    /**
        Declare all fields applicable to this comment, with any display options.
        */
    protected function my_fields()
        {
        $help = new FieldHelp($this->patient);
        return array(
            input_group('Call Type'
                ,input_select('call_type'
                    , array('NC'=>'OK - NO CHANGES'
                        ,'IN'=>'OK - PENDING INS'
                        ,'PI'=>'OK - PENDING INS/PO'
                        ,'PO'=>'OK - PENDING PO'
                    ), 'NC', 1)->label(' ')->reason_swap()
                )->left()
            ,input_group('Copay and Credit Card', 
                input_text('copay', 20)
                ,input_check('charge_cc')
                ,input_text('cc_amt', 20)->label()->mand()
                )->right()
            ,input_group('Please fill in info'
                ,input_hidden('category', 'OK')
                ,input_text('spoke_to', 30, 'PT')->mand()
                ,input_date('ship_date', date("n/j/Y"))->reason_show('call_type', 'nc')
                )->left()
            ,input_group('ED Supply'
                ,input_select('ed_pump',ptdme('L7900'), '', 1)->label('ED Pump ')->mand()
                )->right()
            ,input_group('Additional Notes',
                input_tbox('additional_notes', 3, 80, 250)->label()
                )->whole()
            );
        }

我把它放在类(class)末尾的 php 结束标记之后,但它不起作用。我想这是因为它必须在实际字段之前调用。

任何和所有的帮助将不胜感激。谢谢。

最佳答案

您本身无法在您的类中“执行”javascript,但您可以通过简单地回显它来将其包含在您的页面中...

<?php
  ...

  echo <<<JS
    <script type="text/javascript">
    $(document).ready(function(){
      $('charge_amt').keyup(function(){
        var that = this;
        $('#charge_cc').prop('checked', function(){
          return that.value.length;
        });
      }); 
    });
    </script>

  JS;

  ...
?>

关于php - 是否可以在 php 类中包含 &lt;script type ="text/javascript"> ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16968219/

相关文章:

php - 读取一个 csv 文件并使用 php 创建另一个 csv 文件

php - 如何从 joomla 表中选择所有列?

javascript - Electron Create React App 在构建后未加载

javascript - 当下拉值更改时选择单选按钮

javascript - 从 JavaScript 转换为

javascript - 捕获 div 另一个页面或 jQuery javascript

php - 使用 PHP 从 CSV 导入的数据破坏了隐藏字符

php - 如何将数组第一个值转换为键,第二个值转换为值

javascript - 在javascript中对 "responsive"下拉项进行点击事件

Javascript Div 滚动 - 一些问题