1

今天早上我发布了一个关于 Chosen jQuery 脚本的问题,我是如何使用经典 asp 从选定的 jquery 多选框中检索值的,有人问我要演示代码,所以在构建它时,一切似乎都能正常工作突然好起来了,以为你知道我老了,但是在尝试实现代码后我遇到了同样的问题,但我想我可能已经找到了我正在运行的问题。您将在下面找到所涉及的代码:

这包括选择的 jquery (http://harvesthq.github.com/chosen/) 的 2 种形式,最上面的一种是普通形式,第二种是具有上传功能的形式,我在两个页面下面都包含了代码:

“example.jquery.html”的代码

<!doctype html> 
<html lang="en"> 
<head>
  <link rel="stylesheet" href="chosen/chosen.css" />
</head>
<body>
<h3>Chosen without enctype="multipart/form-data"</h3>
<form action="CollectChosenData.asp?type=plain" method="post" name="ExampleChosen">
<div id="container">
    Multiple Select<br><br>
    <select data-placeholder="Your Favorite Types of Bear" style="width:350px;" multiple class="chzn-select" name="ChosenData" tabindex="8">
        <option value=""></option>
        <option value="1">American Black Bear</option>
        <option value="2">Asiatic Black Bear</option>
        <option value="3">Brown Bear</option>
        <option value="4">Giant Panda</option>
        <option value="5" selected>Sloth Bear</option>
        <option value="6">Sun Bear</option>
        <option value="7" selected>Polar Bear</option>
        <option value="8">Spectacled Bear</option>
    </select>
    <br>
    <br>

    text field:
    <input type="text" name="othertext" value="text value">
    <br>
    <br>
    <input type="submit" name="ExampleChosenSubmit" value="Post form">
  </div>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
  <script src="chosen/chosen.jquery.js" type="text/javascript"></script>
  <script type="text/javascript"> $(".chzn-select").chosen();</script>
  </form>
<br>
<hr>
<br>

<h3>Chosen with enctype="multipart/form-data"</h3>
<form action="CollectChosenData.asp?type=upload" method="post" name="ExampleChosenUpload" enctype="multipart/form-data">
<div id="container">
    Multiple Select<br><br>
    <select data-placeholder="Your Favorite Types of Bear" style="width:350px;" multiple class="chzn-select" name="ChosenData" tabindex="8">
        <option value=""></option>
        <option value="1">American Black Bear</option>
        <option value="2">Asiatic Black Bear</option>
        <option value="3">Brown Bear</option>
        <option value="4">Giant Panda</option>
        <option value="5" selected>Sloth Bear</option>
        <option value="6">Sun Bear</option>
        <option value="7" selected>Polar Bear</option>
        <option value="8">Spectacled Bear</option>
    </select>

    <br>
    <br>

    other field:
    <input type="file" name="mytestfile" value="">
    <br>
    <br>

    text field:
    <input type="text" name="othertext" value="text value">
    <br>
    <br>
    <input type="submit" name="ExampleChosenSubmit" value="Post form">
  </div>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
  <script src="chosen/chosen.jquery.js" type="text/javascript"></script>
  <script type="text/javascript"> $(".chzn-select").chosen();</script>
  </form>
</body>
</html>

==================================================== ==================================================== ==================================================== ===============

'CollectChosenData.asp' 的代码

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
    <title>Untitled</title>
</head>

<body>
<% 
If Request.Querystring("type") = "plain" Then
    Response.write "Value collected from chosen select box: '"& Request.Form("ChosenData") &"'<br/>"
    Response.write "Value collected from text field: '"& Request.Form("othertext") &"'<br/>"
ELseIf Request.Querystring("type") = "upload" Then
    Set objUpload = Server.CreateObject("Persits.Upload")
        objUpload.OverwriteFiles = False
        objUpload.SetMaxSize 1048576    ' Limit files to 1MB
        objUpload.SaveVirtual "/upload"
        Response.write "Value collected from chosen select box: '"& objUpload.Form("ChosenData") &"'<br/>"
        For Each File in objUpload.Files
            Response.write File.FileName &"<br/>"
        Next
        Response.write "Value collected from text field: '"& objUpload.Form("othertext") &"'<br/>"
    Set objUpload = nothing
End if

 %>
<br>
<br>
Return and <a href="example.jquery.html">try again</a>
</body>
</html>

现在为什么第一种形式(普通版)会给我正确的值返回'ChosenData'而第二种形式没有?

非常感谢你们的帮助和回复,他一边挠头一边说......

4

1 回答 1

2

您的问题似乎是上传组件仅显示选择多个值之一。

请参阅“Upload.Form 仅返回多选控件的第一个选定项”

如解决方法所示,您将必须遍历每个名​​为ChosenData和显示的表单元素。

于 2012-09-27T06:14:04.867 回答