2

私はこのhtmlフォームを持っています:

    <form method="post">
        <input type="radio" name="news" id="new" value="nuova" onchange="newstype(this.id);">Nuova News
        <input type="radio" name="news" id="mod" value="modifica" onchange="newstype(this.id);">Modifica News

        <select name="news" id="modifica" style="display:none" onchange="shownews(this.value)">
            <?php
                include "../flock/sql.php";
                $connection = new mysqli($host, $user, $pw, $db) or die("Impossibile connettersi"); 
                $querylistanews = "SELECT * FROM NEWS ORDER BY id DESC";
                $listanews = $connection->query($querylistanews);                       
                    print '<option>Seleziona una news...</option>';                     
                while ($newsdamodificare = $listanews->fetch_object()) {
                    print '<option value="'.$newsdamodificare->id.'">'.$newsdamodificare->data." - ".$newsdamodificare->title.'</option>';
                }
                $listanews->close();
                $connection->close;      
            ?>    
        </select>
    </form>

このJavaScript:

function newstype(param) {
    if(param == 'new') {
        document.getElementById('crea').style.display = 'inline';
        document.getElementById('modifica').style.display = 'none';
        document.getElementById('newsdamodificare').style.display = 'none';
    } else {
        if(param == 'mod') {
        document.getElementById('crea').style.display = 'none';
        document.getElementById('modifica').style.display = 'inline';
        document.getElementById('newsdamodificare').style.display = 'inline';
        }
    }
}

function shownews(str) {

    if (str=="") {
      document.getElementById("newsdamodificare").innerHTML="";
      return;
    } 

    if (window.XMLHttpRequest) {        // codice per IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();     
    } else {                            // codice per IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4 && xmlhttp.status==200) {
        document.getElementById("newsdamodificare").innerHTML=xmlhttp.responseText;
      }
    }

xmlhttp.open("GET","modifica.php?news="+str,true);
xmlhttp.send();
}

そしてこのphp:

<head>
<script type="text/javascript" src="../editor/ckeditor.js"></script>
<script type="text/javascript" src="/js/charscounter.js"></script>
</head>

<?php
$news=$_GET["news"];
include "../flock/sql.php";

$connection = new mysqli($host, $user, $pw, $db) or
  die('Impossibile connettersi al database: ' . mysql_error());

$newsdaldatabase="SELECT * FROM NEWS WHERE id = '".$news."'";

$result = $connection->query($newsdaldatabase);

$count = mysqli_num_rows($result);

if($count==1){
    while($dati = mysqli_fetch_array($result)) {
      $id = $dati['id'];
      $data = $dati['data'];
      $title = $dati['title'];
      $body = $dati['body'];
    }
} else {
    die('Errore del sistema. Più di una news selezionate: ' . mysql_error());
}
mysqli_close($connection);
?>

<div class="normal" id="modifica">
<table style="width:100%;height:100%;">
<tr>
<td colspan="3" border="0">
    <strong class="confirm">Modifica news</strong>
</td>
</tr>

<tr>
<td width="107" align="right">
    <strong>Data</strong>
</td>
<td colspan="2">
<form name="modificanews" method="post" action="italiano.php?modifica=yes">
    <input name="idmodificanews" type="text" style="display:none" value="<?php echo $id ?>">
    <input name="datanewsmodificata" type="text" maxlength="10" size="8" value="<?php echo $data ?>"> gg.mm.aaaa
</td>
 </tr>

<tr>
<td align="right">
    <strong>Titolo</strong>
</td>
<td width="360">
    <input name="modificatitolo" type="text" maxlength="50" size="50" value="<?php echo $title ?>" onKeyPress="return taLimit(this)" onKeyUp="return taCount(this,'myCounter')">
</td>
<td width="522">
          <b><span id=myCounter>50</span></b> caratteri rimanenti per il titolo</font>
</td>
</tr>

<tr>
<td colspan="3">
    <textarea name="modificatesto"><?php echo $body ?></textarea>
        <script>
            CKEDITOR.replace('modificatesto');
        </script>
</td>
</tr>

編集するニュースを選択すると、サーバーからのコンテンツがphpに正しく投稿されますが、HTMLではphpのスクリプト(CKEDITORとChar Cunter)がアクティブではありません。

したがって、私のHTMLでは、ユーザーがニュースを編集する場合、CKEDITORなどの代わりに単純なテキストエリアのみを取得します。

それを修正する方法はありますか?どういうわけか私を助けてくれませんか?

ありがとうございました!

編集:私は自分で問題を解決しました。答えとして解決策を参照してください。

4

2 に答える 2

1

同じ質問がある人のために:

私は次の方法で問題を解決しました:javascriptで新しい行を追加します:

document.getElementById("newsdamodificare").action=CKEDITOR.replace('modificatesto');

この2行の間:

document.getElementById("newsdamodificare").innerHTML=xmlhttp.responseText;
NEW LINE TO INSERT HERE
}

そして、PHPからこれらの行を削除します。

<script>
    CKEDITOR.replace('modificatesto');
</script>

お役に立てれば!

于 2013-01-28T02:43:29.623 に答える
0

名前でテキストエリアを選択しようとしていますが、 IDCKEDITOR.replace('modificatesto');を探しています。

試す

<textarea id="modificatesto"><?php echo $body ?></textarea>
    <script>
        CKEDITOR.replace('modificatesto');
    </script>
于 2013-01-27T07:23:56.513 に答える