我想在我的网站中插入基本表单,以便我的用户可以搜索食谱。我很难从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>
答案 0 :(得分:5)
请勿将其添加到""
引号中。
使用此:
var foodSearch = window.open("http://search.myrecipes.com/search.html?N=17&mFil=false&Ntt=" + document.getElementById("searchFood").value);