0

私の頭を悩ませている何かについての簡単な質問です。ネストされた要素を選択するためにencodeURIComponentを取得できません。具体的には、

encodeURIComponent($(".signs selected_sign > #s2FaceFinish").val());

「未定義の値」を生成するだけです - /online-order2.html?size=1cm%20x%20&width=2cmundefined:

$(function () {
      $("#proceed_button").bind("click", function () {
        var url = "online-order2.html?size="
        + encodeURIComponent($("#height").val())
        + "cm x " + "&width=" 
        + encodeURIComponent($("#width").val()) + "cm" 
        + encodeURIComponent($(".signs selected_sign > #s2FaceFinish").val());
        window.location.href = url;
    });
  });

HTMLは次のとおりです。

<article>
  <form action="" id="sDimensions" onsubmit="return false;">
    <div class="height">
      <input id="height" type="number" maxlength="3" name="SignHeight" value="" />cm height<br>
    </div>
    <div class="width">
      <input id="width" type="number" maxlength="3" name="SignWidth" value="" />cm width<br>
    </div>
  </form>
</article>


<article class="signs selected_sign">
  <form id="s2Options">
    <div class="sign_options>"Face finish: "
      <select name="s2FaceFinish" id="s2FaceFinish">
        <option value="printed">Printed</option>
        <option value="vinyl">vinyl</option>
      </selected>
    </div?
  </form>
</article>
4

1 に答える 1

0

編集、更新

selected_signセレクター内で$(".signs selected_sign > #s2FaceFinish").val() 無効なセレクター (要素/タグhtmlが含まれていないように見える) ?selected_sign

以下に変更

$(".signs .sign_options > #s2FaceFinish").val()

文字列"cm x "にエンコードされていないスペース内に注意してくださいurl

試す

$(function () {
      $("#proceed_button").bind("click", function () {
         var url = "online-order2.html?size="
        + encodeURIComponent($("#height").val() + "cm x ")
        + "&width=" 
        + encodeURIComponent($("#width").val()) + "cm" 
        + encodeURIComponent($(".signs .sign_options > #s2FaceFinish").val());
        console.log(url);
      });
});

jsfiddle http://jsfiddle.net/guest271314/kwqoyt0j/

于 2014-10-06T04:43:29.373 に答える