Javascript 未捕获的类型错误:$(...).value 不是尝试通过 JQuery 发送值时的函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30074935/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught TypeError: $(...).value is not a function when trying to send a value via JQuery
提问by Vladimir Marenus
<!DOCTYPE html>
<html>
<head lang="en">
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<meta charset="UTF-8">
<title>PHP socket chat</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font: 13px Helvetica, Arial; }
form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
form input { border: 0; padding: 10px; width: 100%; margin-right: .5%; }
form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
#messages { list-style-type: none; margin: 0; padding: 0; }
#messages li { padding: 5px 10px; }
#messages li:nth-child(odd) { background: #eee; }
</style>
</head>
<body>
<ul id="messages"></ul>
<form action="">
<input type ="text" id="m" autocomplete="off" />
<input type="submit" value="Submit" onclick="$('#messages').load('send.php', { chat_message: $('#m').value() });" />
</form>
I am seeing an
我看到一个
"Uncaught TypeError: $(...).value is not a function"
“未捕获的类型错误:$(...).value 不是函数”
whenever I submit data, and I'm not sure why. I'm trying to send the data in the text field via POST to send.php.
每当我提交数据时,我不知道为什么。我正在尝试通过 POST 将文本字段中的数据发送到 send.php。
Any help would be appreciated, thanks!
任何帮助将不胜感激,谢谢!
回答by Sougata Bose
There is no function named valuein jquery.
valuejquery 中没有命名函数。
{ chat_message: $('#m').value() }
It should be -
它应该是 -
$('#m').val()
回答by Gurpreet Khattra
$('#messages').load('send.php', { chat_message: $('#m').val() });
$('#messages').load('send.php', { chat_message: $('#m').val() });
回答by Rupinder Kaur
Use this script on you page.
在您的页面上使用此脚本。
<script>
var $ = jQuery.noConflict();
</script>

