怎么用jQuery获取页面上所有类型为textarea但name包含“question”的文本框的值?

解决方案 »

  1.   

    $(textarea[name='question']).each(function(){$(this).attr("value");})试试
      

  2.   

    $("textarea[name*='question']").each( function() {
        alert($(this).val());
    });
      

  3.   


    <!DOCTYPE HTML>
    <html lang="">
    <head>
    <meta charset="gbk">
    <title></title>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    </head>
    <body>
    <textarea name="question">1</textarea>
    <textarea name="question">2</textarea>
    <textarea name="question">3</textarea>
    <textarea name="ques123tion">4</textarea>
    <textarea name="question123">5</textarea>
    <script type="text/javascript">
    $('textarea[name*=question]').each(function(){
    alert( this.value )
    })
    </script>
    </body>
    </html>
    这个是包含question, question123也匹配
    楼主是要等于的 还是包含的?
    等于就直接textarea[name=question]
      

  4.   

    这样:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
        <title>test</title>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    </head>
    <body>
    <textarea name="questionName" id="" cols="30" rows="10">111</textarea>
    <textarea name="Namequestion" id="" cols="30" rows="10">222</textarea>
    <textarea name="Name" id="" cols="30" rows="10">333</textarea>
    <script type="text/javascript">
        var tarea = $("textarea[name*='question']");
        tarea.each(function(){
            console.log($(this).val());
        });
    </script>
    </body>
    </html>
      

  5.   

    $("textarea[name='question']").each(function(){alert($(this).attr("value"));})