我想使用click()函数在HTML中返回表单的属性和值,然后将它们添加到字符串中。 这是我的代码。对于“表单”,我只想获得这些值一次,而“输入”标签可以被多次检索:
var target="http://www.aaa.com/";
var clicktime=0;
$(document).ready(function(){
$("form").click(function(){
var c=this.method;
var d=this.action;
var e=d.substr(17)
$("#test2").text("the method is: " +c+" "+"The action part is:"+ " "+e);
if (clicktime=0){
target=target+e+"?";
}
clicktime=1;
$("#test1").text("you choose the following links:"+ " "+target);
});
});
$(document).ready(function(){
$("input").click(function(){
var a=this.name;
var b=this.value;
target=target+a+"="+b+"&";
$("#test1").text("you choose the following links:"+ " "+target);
});
});
点击浏览器中的表单部分后,结果应如下所示:
the method is get The action part is /dec/DEC
you choose the following links: http://www.aaa.com/
虽然我在浏览器中单击表单部分的结果是:
the method is get The action part is /dec/DEC
you choose the following links: http://www.aaa.com/dec/DEC
“target = target + e +”?“;没有用!为什么?类似的功能在”输入“功能上运行良好!
答案 0 :(得分:4)
if (clicktime=0)
应该是
if (clicktime==0)
=
是一个赋值运算符。
==
是比较运算符。