0

我想在我的网站中插入一个基本表单,以便我的用户可以搜索食谱。我很难让 javascript 从表单中找到输入值。任何帮助,将不胜感激。

<!DOCTYPE html>
<html>
<head>
<script>
  function searchURL()
{
    var foodSearch =  window.open("http://search.myrecipes.com/search.html?N=17&mFil=false&Ntt=" + "document.getElementById("searchFood").value");

};
  </script>
  </head>

<body>

<form>

<fieldset>
<legend>Search for Healthy Diet Recipes</legend>
<p>
Type in the name of the Recipe or Healthy Diet Food you would like to cook below:<br>
</p>
<br>
<input type="text" id='searchFood' >
<input type="button" value="Find Delicious Food" onClick="searchURL()">

</fieldset>
</form>
</body>

</html>
4

1 回答 1

5

不要将其添加到""引号中。

用这个:

var foodSearch = window.open("http://search.myrecipes.com/search.html?N=17&mFil=false&Ntt=" + document.getElementById("searchFood").value);
于 2013-07-16T20:29:51.997 回答