简体   繁体   English

$('#'+ CommentBoxId).val(); 没有接受

[英]$('#' + CommentBoxId).val(); not picking up

User enters data in comment box and clicks corresponding submit btn. 用户在评论框中输入数据并单击相应的提交btn。 Im trying to pass id, CompanyId, WorkId, CommentBoxId to code behind to update the record. 我试图将id,CompanyId,WorkId,CommentBoxId传递给后面的代码来更新记录。 So far this all works fine, but I also want to pass the data entered in the commentbox. 到目前为止,一切正常,但我也想传递评论框中输入的数据。

JavaScript runtime error: Sys.Net.WebServiceFailedException: The server method 'CommentBox' failed with the following error: System.InvalidOperationException-- Invalid web service call, missing value for parameter: 'CommentBoxContents'.

The values of id, CompanyId, WorkId and CommentBoxId, are all passed correctly. id,CompanyId,WorkId和CommentBoxId的值都正确传递。 so how can i pass what is entered in the text box? 那么如何通过文本框中输入的内容? thank you 谢谢


EDIT: 编辑:

<script type="text/javascript" language="javascript">
   var commentBoxData
   function SubmitButton(id, CompanyId, WorkId, CommentBoxId) 
   {
       var commentBoxData = $('#'+CommentBoxId).val();
        Functions.CommentBox(id, CompanyId, WorkId, commentBoxData);
   }
</script>

//Inside a repeater: //在转发器内:

<th style="width:200px;">
     <input id="Comments" name='<%# GetIdOfCommentBox((int)Eval("id")) %>' 
             type="text" runat="server" value='<%# Bind("Comment") %>' />
    <input id="SubmitComments" type="button"
           onclick="SubmitButton('<%# Eval("id") %>','<%# Eval("CompanyId") %>',
                        '<%# Eval("WorkId") %>','<%# Eval("CommentId") %>');"  />
</th>

You are using $(CommentBoxId).val() which is wrong. 您正在使用$(CommentBoxId).val()这是错误的。

     function SubmitButton(id, CompanyId, WorkId, CommentBoxId) 
     {
         $('#'+CommentBoxId).val();

        Functions.CommentBox(id, CompanyId, WorkId,  $('#'+CommentBoxId).val(), Test);  
     }

please use $('#'+CommentBoxId).val() in the Functions.CommentBox 请在Functions.CommentBox使用$('#'+CommentBoxId).val()

You could try re-writing your code like this: 您可以尝试重写这样的代码:

function SubmitButton(id, CompanyId, WorkId, CommentBoxId) 
{
   var commentBoxId = $('#'+ CommentBoxId).val();
   Functions.CommentBox(id, CompanyId, WorkId,  commentBoxId, Test);  
}

** UPDATE ** ** 更新 **

And inside the repeater, the textbox id should be the same as the SubmitButton 's CommentBoxId parameter: 在转发器内部,textbox id应该与SubmitButtonCommentBoxId参数相同:

<th style="width:200px;">
     <input id="CommentId" name='<%# GetIdOfCommentBox((int)Eval("id")) %>' 
             type="text" runat="server" value='<%# Bind("Comment") %>' />
    <input id="SubmitComments" type="button"
           onclick="SubmitButton('<%# Eval("id") %>','<%# Eval("CompanyId") %>',
                        '<%# Eval("WorkId") %>','<%# Eval("CommentId") %>');"  />
</th>

This line does nothing effective because you are not storing the result of the val() call 此行没有任何效果,因为您没有存储val()调用的结果

$('#'+CommentBoxId).val();

The call to Functions.CommentBox will have a null value for the fourth parameter because you are not prefixing the id with the hash. Functions.CommentBox的调用将为第四个参数设置一个空值,因为您没有为id添加哈希前缀。

Try this: 尝试这个:

var commentBoxIdVal = $('#'+CommentBoxId).val();
Functions.CommentBox(id, CompanyId, WorkId, commentBoxIdVal, Test);  

看起来您的输入的ID为“评论”,但您尝试在通话中使用“CommentId”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM