【问题标题】:JQTE Text value getting Style tooJQTE Text 值也获得 Style
【发布时间】:2015-07-01 20:55:35
【问题描述】:

我尝试在 JQTE 文本编辑器中获取值。我只想获取没有任何 HTML 元素或设计的值。

我试过这个总线,当我在 UI 上做一些样式时,它也给了我值中的样式。但我只想要没有风格的价值。任何帮助对我来说都会很棒。

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Crea Application</title>

    <link href="css/jquery-te-1.4.0.css" rel="stylesheet">



    <!--[if lt IE 9]>
    <script src="../js/thirdparty/jquery-1.11.2.js"></script><![endif]-->
    <!--[if gte IE 9]><!-->
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js" charset="utf-8"></script>
    <!--<![endif]-->
    <script src="js/thirdparty/jquery-te-1.4.0.min.js"></script>
    <!-- <script src="js/thirdparty/jquery.cookie.js"></script>
    <script src="js/thirdparty/jquery.loadmask.min.js"></script>
    <script src="js/thirdparty/jquery.maskinput.js"></script>
    <script src="js/thirdparty/jquery.bpopup.js"></script>

    <script src="js/thirdparty/jquery-date-time.js"></script>
    <script src="js/thirdparty/jquery.datetimepicker.js"></script>

    <script src="js/thirdparty/jquery-timepicker.js"></script>
    <script src="js/thirdparty/jquery-center.js"></script>
    <script src="js/thirdparty/jquery.jqdock.js"></script>
    <script src='js/thirdparty/jquery.scrollto.js'></script>
    <script src='js/thirdparty/moment.js'></script>
    <script src='js/thirdparty/bowsy.js'></script> -->

</head>
<body>


 <textarea  cols="2" rows="3" name="textarea" class="jqte-test"  id="mytextarea"></textarea>


<button class="status">Toggle jQTE</button>

    <script type="text/javascript">

     $(".status").click(function()
     {
       // alert($("textarea#mytextarea").html());
        jqteStatus = jqteStatus ? false : true;
        $('.jqte-test:first').jqte({"status" : jqteStatus});
        console.log($("#mytextarea").html());
         jqteStatus = jqteStatus ? false : true;
        $('.jqte-test:first').jqte({"status" : jqteStatus});
      });
    </script>
</body>
</html>

【问题讨论】:

    标签: javascript jquery html textbox jqte


    【解决方案1】:

    由于该字段嵌套在 jqte 块内,因此您可以向上 DOM 以达到仅允许获取文本的级别:

    例如,如果您的字段是“电子邮件主题”:

    $("#emailsubject").closest(".jqte").find(".jqte_editor").eq(0).text();
    

    因此,在 DOM 上向上我们找到最接近的样式为“.jqte”的元素,然后我们在 DOM 中向下查找下一个样式为“.jqte_editor”。由于这将是一个 jQuery 对象,我们需要使用 .eq(0) 获取第一次出现,最后使用 .text() 获取文本

    【讨论】:

      【解决方案2】:

      您可以简单地删除 HTML 格式:

      var myContent = $('.jqte-test').val();        
      var final = $(myContent).text();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-10-18
        • 2011-08-29
        • 1970-01-01
        • 1970-01-01
        • 2017-10-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多