Javascript输出未定义,代码似乎没问题

时间:2015-09-23 05:26:26

标签: javascript php codeigniter

我有一个基于codeigniter的网站。我正在尝试输出用户信息以打印出他们的运输标签。一切正常,但新弹出窗口中显示的信息格式不正确,其中一个参数未定义。我正在使用的代码如下:

来自admin_controller.php

public function address(){
        $data['Address']=$this->input->get("Address");
        $data['firstname']=$this->input->get("firstname");
        $data['lastname']=$this->input->get("lastname"); 
        $data['address1']=$this->input->get("address1");
        $data['address2']=$this->input->get("address2");
        $data['suburb']=$this->input->get("suburb");
        $data['state']=$this->input->get("state");
        $data['postcode']=$this->input->get("postcode");
        $data['mobile']=$this->input->get("mobile");
        $this->load->view('admin/address',$data);
    }

与按钮本身相关的代码

<a class="btn btn-primary" href="#" onClick="Address('<?php echo $order->firstname ?>','<?php echo $order->lastname ?>','<?php echo $order->address1 ?>','<?php echo $order->address2 ?>','<?php echo $order->suburb ?>','<?php echo $order->state ?>','<?php echo $order->postcode ?>','<?php echo $order->mobile ?>')"> Label </a>

剧本

<script>
    function Address(val,firstname,lastname,address1,address2,suburb,state,postcode,mobile){
       window.open("<?php echo base_url();?>admin_controller/address?Address="+val+"&firstname="+firstname+"&lastname="+lastname+"&address1="+address1+"&address2="+address2+"&suburb="+suburb+"&state="+state+"&postcode="+postcode+"&mobile="+mobile+"",null,"width=800,height=400,left=100,top=100");
    }

</script>

1 个答案:

答案 0 :(得分:4)

您没有将参数val的值传递给Javascript函数。

onClick="Address('<?php echo $order->firstname ?>'

应该是这样的:

onClick="Address('theValue', '<?php echo $order->firstname ?>'