只是一个快速的问题,有些东西让我的大脑感到震惊。我不能让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>
答案 0 :(得分: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);
});
});