0

我正在使用 jquery 在按钮单击事件上验证 CKeditor 中存在的数据。单击按钮后,它将正确答案列表和错误答案列表分开。这工作正常。但是在修改了错误的答案并点击按钮后,它再次采用最初输入的值。如何使其在第二次单击按钮时获取修改后的数据。

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="../ckeditor/ckeditor.js"></script>
<script src="../ckeditor/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
 $(document).ready(function () {

     CKEDITOR.replace('Field');

     var correctZips = new Array;
         var wrongZips = new Array;
     var CorZip;
     var WorZip;

     $('#save').click(function () {

        var editor_data = CKEDITOR.instances['Field'].getData();
        var element = $(editor_data).text().split(",");

            $.each((element), function (index, value) {
            if(this.length=5 && jQuery.isNumeric(this)) {
                    correctZips= correctZips+"<span>"+this+"</span>"+",";


                }else {
                    wrongZips= wrongZips+"<span id='flip' style=\"background-color: yellow; \">"+this+"</span>"+",";
                }
            }
            )   


            CKEDITOR.instances.Field.setData((correctZips + wrongZips), function (index, value){

            })
        //$("#save").attr("disabled", "disabled");       
     });         
 });

</script>
</head>
<body>
<textarea id="Field"></textarea>
<button id ="save">Verify the ZipCodes</button>
</body>
</html>

问候,史蒂文

4

1 回答 1

0

您将 2 个ZIPS变量定义为单击处理程序之外的数组。您需要在每次单击时重置它们,因此需要在处理程序中定义它们,并且不应将它们定义为数组,因为您使用它们来连接字符串

 $('#save').click(function () {
      var correctZips = '', wrongZips='';/* start with empty strings*/
      /* remainder of your handler code*/
 });
于 2012-10-30T12:29:34.913 回答