-1

我有一个用户可以填写的表格,我需要用户能够使用查询字符串示例生成带有结果的 pdf

<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>

谢谢!

4

2 回答 2

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/

于 2011-03-07T00:55:58.833 回答
1

这将采用值 opt1 和 opt2 并将其作为 opt1=x&opt2=y 放入 url。

  <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>
于 2011-03-07T01:10:19.360 回答