Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用javascript从输入框中获取值_Javascript_Jquery - Fatal编程技术网

使用javascript从输入框中获取值

使用javascript从输入框中获取值,javascript,jquery,Javascript,Jquery,我有一个表单,希望将一个值从它传递到我的javascript,并使用这个值创建一个javascript变量 我是javascript的新手,无法让它工作 这是我的密码: <input id="bartype" name="bartype" type="text" value="<?php echo $bartype; ?>" style="display:none" /> 我该怎么做 非常感谢 var type = $('#bartype').val(); var ta

我有一个表单,希望将一个值从它传递到我的javascript,并使用这个值创建一个javascript变量

我是javascript的新手,无法让它工作

这是我的密码:

<input id="bartype" name="bartype" type="text" value="<?php echo $bartype; ?>" style="display:none" />
我该怎么做

非常感谢

var type = $('#bartype').val();
var targetUrl = 'listing.php?page='+type;
使用google开发者工具或firebug调试javascript

console.log($('#bartype'))
您应该阅读一些教程:

使用google开发者工具或firebug调试javascript

console.log($('#bartype'))
您应该阅读一些教程:


google“jQuery值”,第一个结果就是你的答案。为什么不先试试手动呢?JavaScript在客户端工作;PHP与此无关,请在询问JavaScript问题时发布客户端(相关)HTML,而不是生成它的服务器端脚本。谢谢,我会记住这一点;)谷歌“jqueryvalue”,第一个结果就是你的答案。为什么不先试试手动呢?JavaScript在客户端工作;PHP与此无关,请在询问JavaScript问题时发布客户端(相关)HTML,而不是生成它的服务器端脚本。谢谢,我会记住这一点;)实际上,它并没有按我所希望的那样工作。。当我检查HTML时,表单部分看起来是正确的:但是javascript没有得到类型。如果我硬编码它工作的类型:var targetUrl='listing.php?page=vip';但不是这样:var targetUrl='listing.php?page='+type;有什么想法吗?$(function(){var type=$('#bartype').val();var targetUrl='listing.php?page='+type;console.log($('#bartype').length)})你应该把所有的jQuery代码都封装在这段代码$(function(){})中,这是它实际上没有按我想要的方式工作的快捷方式。。当我检查HTML时,表单部分看起来是正确的:但是javascript没有得到类型。如果我硬编码它工作的类型:var targetUrl='listing.php?page=vip';但不是这样:var targetUrl='listing.php?page='+type;有什么想法吗?$(function(){var type=$('#bartype').val();var targetUrl='listing.php?page='+type;console.log($('#bartype').length)})您应该将所有jQuery代码包装在代码$(function(){})中,这是