0
我想使用click()函数返回HTML中表单的属性和值,然后将它们添加到字符串中。 这是我的代码。对于“形式”,我只想得到这些值一次,而“输入”标签可以被检索多次:JavaScript:为什么代码在点击功能上不起作用
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
“目标=目标+ E +”“;没有工作,为什么类似的功能,效果很好!? Ø n“输入”功能!
@AlienArrays如果只使用数字,则不适用。对于字符串,是的。 –