我需要用 jquery 处理这段代码。
我需要获取作为关键字的文本框的值,点击链接将重定向。
所以我很难从文本框中获取该值,然后运行重定向。这是这条线 $("#serviceorder").val("keyword");
HTML 代码:
<html>
<input id="serviceorder" type="text" data-bind="value: keyword" />
<a href="" id="g-search-button"></a>
</html>
JS代码:
$("#g-search-button").click(function (event) {
event.preventDefault();
$("#serviceorder").val("keyword");
var keyword = event.currentTarget.value;
if (keyword.length > 0) {
window.location.href = "URL + encodeURIComponent(keyword);
return false;
}
});