Home Backend Development PHP Tutorial JS参数传递,该如何解决

JS参数传递,该如何解决

Apr 01, 2017 pm 03:59 PM

JS参数传递

现用Smarty做网站,想把在html页面中JS计算出来的变量fee提交到一个php处理页面去,用语句

document.frm.action="?do=info&action=submit&id=<!--{$meminfo1.member_id}-->&fee=fee";
Copy after login
Copy after login

在php中获取:

$fee=empty($_GET['fee'])?'':trim($_GET['fee']);
Copy after login

不过就是传递不过来,请问各位大虾正解如何?(JS中代码如下)

<SCRIPT Language = javascript>
function fee(){
  var num=0;
var num1=0;
var sum=0;
var fee=0;
var value=10;
  var boxObj = document.getElementsByName("checkbox[]");
var cbox = document.getElementsByName("cbox[]");
  
  for(i=0;i<boxObj.length;i++){
  if(boxObj[i].checked){
  num++;
  }
  }
for(i=0;i<cbox.length;i++){
  if(cbox[i].checked){
  num1++;
  }
  }
sum=num+num1;
fee=sum*value;
  if(!confirm("您一共选择了"+sum+"条收费项目,查看所选收费项目将从您的账户扣除"+fee+"元。是否确认支付?")) 
  {return false;}
else {
document.frm.action=&quot;?do=info&amp;action=submit&amp;id=&lt;!--{$meminfo1.member_id}--&gt;&amp;fee=fee&quot;;document.frm.submit();}  
}
</script>
Copy after login

------解决方案--------------------
确实对新手来讲由于缺少必要的条理逻辑,所以只能用简单的传值方式来实现页面间值得传递,由于我也是新手了所以也只能说说我的困惑,我用js获取本页的文本结点然后通过异步请求将值传递到后台页面,然后打开后台php页面发现传递过来的值不可以直接运用,就是本身后台页面就是用来显示的,显示的东西和传递过来的值密切相关。怎么才能将上个页面传递过来的值直接用于显示呢?
------解决方案--------------------
你的代码还是用代码格式贴出来吧,这样看的很不舒服捏!
------解决方案--------------------
你最好打开编译后的文件,看看

document.frm.action=&quot;?do=info&amp;action=submit&amp;id=&lt;!--{$meminfo1.member_id}--&gt;&amp;fee=fee&quot;;
Copy after login
Copy after login


变成了什么
------解决方案--------------------

document.frm.action=&quot;?do=info&amp;action=submit&amp;id=&lt;!--{$meminfo1.member_id}--&gt;&amp;fee=&quot;+fee;
Copy after login

 以上就是 JS参数传递,该如何解决 的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Best practices for optimizing Golang function parameter passing performance Best practices for optimizing Golang function parameter passing performance Apr 13, 2024 am 11:15 AM

Best practices for optimizing Golang function parameter passing performance

Detailed explanation of C++ function parameters: Performance optimization of parameter passing in parallel programming Detailed explanation of C++ function parameters: Performance optimization of parameter passing in parallel programming Apr 27, 2024 pm 02:09 PM

Detailed explanation of C++ function parameters: Performance optimization of parameter passing in parallel programming

Research on parameter passing methods in Go language Research on parameter passing methods in Go language Apr 03, 2024 pm 02:48 PM

Research on parameter passing methods in Go language

C++ function pointer parameter passing mechanism C++ function pointer parameter passing mechanism Apr 19, 2024 pm 02:06 PM

C++ function pointer parameter passing mechanism

golang function map passed as parameter golang function map passed as parameter Apr 22, 2024 am 11:42 AM

golang function map passed as parameter

The relationship between C++ function parameter passing methods and variable parameter functions The relationship between C++ function parameter passing methods and variable parameter functions Apr 13, 2024 am 08:30 AM

The relationship between C++ function parameter passing methods and variable parameter functions

What is the parameter passing method for PHP functions? What is the parameter passing method for PHP functions? Apr 10, 2024 am 11:06 AM

What is the parameter passing method for PHP functions?

How to write a function with output parameters (called by reference) in Python? How to write a function with output parameters (called by reference) in Python? Sep 02, 2023 pm 04:21 PM

How to write a function with output parameters (called by reference) in Python?

See all articles