0

ユーザーがデータベーステーブルでクリックした情報を取得するjquery関数があります。ユーザーはマウスオーバー時に強調表示される10行のいずれかを選択でき、ユーザーが強調表示された行をクリックすると、関数がそれを取得してテキストボックスに配置します。 。次に、ユーザーがこの購入リクエストを送信した場合、注文フォームである次のページのテキストボックスをエコーし​​ます。

以下のコードは、URLから情報を取得しようとするまではうまく機能します。URLで次のページに渡されていることがわかりますが、2日間試しても、取得できませんでした。ここからどこへ行けばいいのかわからない。誰かがこれを見て、私が正しくコーディングしていないか、何か間違ったことをしていないかどうかを確認できますか?適用されるコードをコピーしました...

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">


$(document).ready(function(){
  $("table tr").click(function(){
       $("#txttread").val($.map($(this).children('td:not(:eq(7))'), function (item) { return $(item).text() }).join(' - '));
  });
});


$(document).ready(function() {

    $('.pickme tr').not(':first').hover(
        function() { $(this).addClass('highlight'); },
        function() { $(this).removeClass('highlight'); }
    ).click( function() {
        $('.selected').removeClass('selected');
        $(this).addClass('selected').find('input').attr('checked','checked');
    });
});


</script>
</head>
<body>
<form action="Order.html" method="GET" name="myform2" />



<div>
<div style="text-align:left height:250px;">
<DIV STYLE="font-family: Arial Black;
color: black; font-size: 20pt;">

Select from inventory below:<br/><input type="text" style="width:500px; height:35px;" rows="1" STYLE="font-family: Arial Black;
color: red; font-size: 20pt;" name="txttread" id="txttread" DISABLED /></div></div></div>
<div>
<div style="text-align:center;">



<br/><input type="button" button id="getone" name="getone" value="Submit your request for purchase" onclick="window.location.href = 'http://localhost/order.html?txttread='+ ( $('#txttread').val() )"><br/><hr/>
</body>
</html>

次のページのURLは...です。

    http://localhost/order.html?txttread=Firestone - All Season - FR-710 - 225/60/16 - 4 - 3 - 60.00
4

2 に答える 2

1

これは、URL が正しくエンコードされていないことに関係していると思います。を追加する最後の行で$('#txttread').val()、次のようにラップする必要がありencodeURIComponent()ます。

<input type="button" 
       button id="getone" 
       name="getone" 
       value="Submit your request for purchase" 
       onclick="window.location.href = 'http://localhost/order.html?txttread=' + encodeURIComponent($('#txttread').val());">
于 2012-06-02T15:05:00.870 に答える
1

これはあなたの質問に完全には答えないかもしれませんが、次のことを考慮してください。

window.location.href = 'http://localhost/order.html?txttread='+ ( $('#txttread').val() )

パラメータを渡すときは、適切なエスケープを適用する必要があります。

window.location.href = 'http://localhost/order.html?txttread=' + encodeURIComponent( $('#txttread').val() );

txttreadHTML ページからの値にアクセスするには:

function getParameterByName(name)
{
  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  var regexS = "[\\?&]" + name + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.search);
  if(results == null)
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}

ここにあるように: https://stackoverflow.com/a/901144/1338292

于 2012-06-02T15:02:09.160 に答える