只是一个快速的问题,它正在破坏我的大脑。我无法让 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>