javascript函数没有获得textarea的值 [英] javascript function not getting value of textarea
问题描述
所以,我有这个jquery函数。
So, I have this jquery function.
<script type="text/javascript">
$(document).ready(function () {
$('#answ').hide();
$("#btnsubmit").click(function () {
var tbans = $('<%= txtMain.ClientID %>').val();
alert(tbans);
$('#answ').toggle();
return false;
});
});
</script>
<textarea id="txtMain" runat="server" rows="20" cols="150" ></textarea>
<input type="submit" id="btnsubmit" />
现在,当我点击提交按钮时,而不是显示用textarea写的文字显示警告说未定义。切换功能虽然有效。
我缺少什么?
P.s我正在使用tinymce texteditor插件和我的textarea。
更新1:
我尝试使用这样的asp按钮。
Now, when I click on submit button, instead of showing the text written in textarea it shows alert that says,"undefined". Toggle function works though.
What I am missing?
P.s I am using tinymce texteditor plugin with my textarea.
UPDATE 1:
I tried using asp button like this.
<asp:Button ID="btnsubmit" runat="server" Text="Submit" Font-Bold="True"
CssClass="style10" BackColor="Gainsboro" Font-Size="Medium"
ToolTip="Submit Answer." UseSubmitBehavior="false" /><br />
然后它会在点击提交时显示提示中textarea的值按钮和切换工作。但随后页面刷新和切换消失。此外,如果我从按钮中删除UseSubmitBehavior =false,那么页面不会再次刷新,它不会显示textarea的值。
更新2:我正在使用与我的textarea一起使用tinyMce texteditor。 tinymce是一位着名的texteditor。我检查了删除tinymce然后代码工作。但事实是,当我使用带有UseSubmitBehavior =false的asp.net按钮时,代码甚至可以使用tinymce,只需在单击提交按钮后刷新页面。
then it shows the value of textarea in alert on click of Submit button and toggle works. But then page refreshes and toggle disappears. Also, if I remove UseSubmitBehavior="false" from button then page doesnt refresh but again, it doesnt show me the value of textarea.
UPDATE 2: I am using tinyMce texteditor with my textarea. tinymce is a well known texteditor. I checked removing tinymce and then code worked. But thing is, the code even worked with tinymce when I took asp.net button with UseSubmitBehavior="false", just it refreshed the page after clicking submit button.
推荐答案
(document).ready(function(){
(document).ready(function () {
('#sickes')。hide();
('#answ').hide();
(#btnsubmit) .click(function(){
var tbans =
("#btnsubmit").click(function () { var tbans =
这篇关于javascript函数没有获得textarea的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!