2011-03-07 69 views
-1

我有一个表格,用户可以填写和我需要的用户能够使用查询字符串 例如使用jQuery生成的查询字符串,JavaScript或PHP

<head> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> 
</head> 
<body> 
<form id="form"> 
<select name="test" id="test"> 
<option id="op1" value="1">1234</option> 
<option id="op2" value="2">2134</option> 
</select> 
</form> 


<a href="url.pdf?Name=[FillStringHere]"> click here</a> 
</body> 

由于产生对自己的成绩PDF文件!

+1

FillStringHere应该如何生成? – 2011-03-07 00:48:35

+0

它应该生成用户选择的值 – jackson5 2011-03-07 00:59:36

+2

为什么你不只有表单POST? – 2011-03-07 01:00:42

回答

1

HTML:

<a href="#" id="pdf_a">click here</a> 

jQuery的

$(document).ready(function(){ 
    $('#pdf_a').click(function(){ 
    $(this).attr('href', 'url.pdf?'+$('#form').serialize()); 
    }); 
}); 

实施例:

http://jsfiddle.net/NeL5X/

+0

请问你能告诉我一个如何使用它的例子吗?我不太喜欢javascript – jackson5 2011-03-07 01:02:54

+0

@小提琴添加。请阅读评论。 – Kyle 2011-03-07 01:07:13

+0

这是完美的!我在开始时并没有意识到它,但现在我明白了!非常感谢你!我有一百万次使用这个.. – jackson5 2011-09-25 20:19:23

1

这将需要的值OPT1和OPT2并把它在URL作为OPT1 = X & opt2 = y。

<head> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> 
    <script type="text/javascript"> 
    $(document).ready(function(){ 
     $("#my_link").click(function(){ 
     opt1 = $("#opt1").val(); // Stores the value of id-opt1 in the variable opt1 
     opt2 = $("#opt2").val(); // Stores the value of id-opt2 in the variable opt2 
     url = "url.pdf?opt1=" + opt1 + "&opt2=" + opt2; // Takes the above variables and creates the query to send to your file. 
     window.location = url; 
     }); 
    }); 

    </script> 
    </head> 
    <body> 
    <form id="form"> 
    <select name="test" id="test"> 
    <option id="op1" value="1">1234</option> 
    <option id="op2" value="2">2134</option> 
    </select> 
    </form> 
    <a id="my_link"> click here</a> 
    </body> 
+0

你有一个锚在'body'标签之外。 – Kyle 2011-03-07 01:16:10

+0

哈哈! :D修正了它! – DMin 2011-03-07 01:18:58

+0

谢谢!如何我这样做,如果我也想显示一些元素的文本值和其他一些查询字符串的实际值? – jackson5 2011-03-07 03:47:50