English 中文(简体)
• 如何在酒类中获取字塔的价值?
原标题:how to get the value of a textarea in jquery?

i 具有这种形式,并试图从案文领域获得价值。 出于某种原因,它不想。

<form action="/profile/index/sendmessage" method="post" enctype="application/x-www-form-urlencoded">
    <div class="upload_form">
        <dt id="message-label"><label class="optional" for="message">Enter Message</label></dt>
        <dd id="message-element">
        <textarea cols="60" rows="5" id="message" name="message"></textarea></dd>
        <dt id="id-label">&nbsp;</dt>
        <dd id="id-element">
        <input type="hidden" id="id" value="145198" name="id"></dd>
        <dt id="send_message-label">&nbsp;</dt>
        <dd id="send_message-element">
        <input type="submit" class="sendamessage" value="Send" id="send_message" name="send_message"></dd>
    </div>
</form>


$("input.sendamessage").click(function(event) {
    event.preventDefault();

    var message = $( textarea#message ).html();
    var id      = $( input#id ).val();

    console.log(message +  -  + id);
});

http://jsfiddle.net/patrioticcow/SvbZJ/1/>jsfiddle

是否有任何想法?

最佳回答
问题回答

页: 1

var message = $( #message ).val();

document.getElementById("message").value

页: 1

var message = $( textarea#message ).val();

You can directly use

var message = $( #message ).val();

在你使用阀(阀)之前,你应检查字塔是否无效,否则,你就会发现不明确的错误。

if ($( textarea#message ) != undefined) {
   var message = $( textarea#message ).val();
}

然后,你可以做任何事。

你们可以直接使用

var message = $.trim($("#message").val());

阅读更多@ 采用“公平”法()

您也可通过要素获得价值。

var message = $("#formId textarea[name=message]").val();

$(文本area#message > may be of length 0 and subsequently $ (textarea#message ).val(s alls

所有数值一律采用<代码>val()。

参看《刑法》指南:

var message = $( #message ).val();

无需使用<代码>.html()。 页: 1

https://api.jquery.com/val/“rel=“nofollow noreferer”>.val(:

<代码>val()方法主要用来获取诸如input>、textarea/code>等形式要素的数值。 当要求进行空洞收集时,它返回<条码>未界定

var message = $( #message ).val();




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.