var name = $('textarea#myTextBox').val();不返回字符串?
我试图使用
var name = $('textarea#myTextBox').val();
从文本区域中获取字符串值但是,这似乎输出未定义。我知道这一点是因为我在这段代码之后检查了我的 JS name = "5"+name+"4";
然后我使用 name
将 name
发送到 C++ 文件Awesomium,名称是通过以下行处理的:
String name = Convert::toString(params[L"name"].toString());
当我看到我的名称设置为什么时,它显示为“5undefined4”
编辑:我的 CSS 就是这样:
#myTextBox {
position: absolute;
top: 78%;
left: 40%;
}
我已将 html 设置为:
<textarea id="myTextBox" rows="1" col="20" maxlength="18"></textarea>
这使得文本区域“监听”CSS 并放置在正确的位置,但我得到 null
作为我的字符串。
我也尝试过:
<div class="myTextBox">
<textarea id="nameBox" rows="1" col="20" maxlength="18"></textarea>
</div>
那么 textarea 不会监听 CSS,它仍然返回 null
I'm trying to get the String value out of a text area using
var name = $('textarea#myTextBox').val();
However, this seems to output undefined. I know this because I have a check in my JS after this code that says name = "5"+name+"4";
I then send name
to a C++ file using Awesomium, and the name is processed through the below line:
String name = Convert::toString(params[L"name"].toString());
When I see what my name is set to, it reads "5undefined4"
EDIT: My CSS is simply this:
#myTextBox {
position: absolute;
top: 78%;
left: 40%;
}
I've had my html set as:
<textarea id="myTextBox" rows="1" col="20" maxlength="18"></textarea>
Which makes the text area "listen" to the CSS and be placed in the correct position, but I get null
as my string.
I've also tried:
<div class="myTextBox">
<textarea id="nameBox" rows="1" col="20" maxlength="18"></textarea>
</div>
Which then the textarea does not listen to the CSS and it still returns null
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的选择器不正确。
为了使该选择器正常工作,您的 HTML 应该类似于...
id
属性是重要的。Your selector is incorrect.
For that selector to work, your HTML should look like...
The
id
attribute is the important one.我将 jquery 与 id 一起使用的方法是使用 $('#controlId')
你尝试过 $('#myTextBox').val() 吗?
The way I would use jquery with id is to use $('#controlId')
did you try $('#myTextBox').val() ?